Laravel 5 Payum provider not working - laravel

I have installed payum for laravel 5 but my providers are not updating correctly.
I added 'Payum\LaravelPackage\PayumServiceProvider' to app/config/app.php file.
'providers' => [
...
//All my providers
'Payum\LaravelPackage\PayumServiceProvider',
],
also tried as
'providers' => [
...
//All my providers
Payum\LaravelPackage\PayumServiceProvider::class,
],
anyway the error message i get whenever i try to use artisan to make a controller or any other thing is:
am i missing any configuration for the service provider? any help will be apreciated.
EDIT: i have created a new provider and stopped using the default provider.
i ran php artisan make:provider PayumServiceProvider
and into its register method pasted:
...
public function register()
{
$this->app->resolving('payum.builder', function(\Payum\Core\PayumBuilder $payumBuilder) {
$payumBuilder
// this method registers filesystem storages, consider to change them to something more
// sophisticated, like eloquent storage
->addDefaultStorages()
->addGateway('paypal_ec', [
'factory' => 'paypal_express_checkout',
'username' => 'EDIT ME',
'password' => 'EDIT ME',
'signature' => 'EDIT ME',
'sandbox' => true
]);
});
}
...
Still not working

Related

Routes missing for Laravel Backpack admin

We have several Laravel applications that use Backpack for the admin panel. A developer wrote a package that used Single sign-on. We have removed this package as it was not working correctly. Once Composer was used to updating Laravel and remove the package, there are NO routes to deal with admin login. Our applications use Laravel 5.8/6 and Backpack 3.6/4.0.
I created another test application with Laravel 5.8 using Backpack 3.6, and the routes are available for login. As you can see, all the login routes are available.
If you look at the following image, you can see the login routes are all missing.
Is there a way to add the routes in again? Laravel Backpack is still installed, but I need to re-register the routes.
All the settings in the application are set to default. I have even made the default authentication guard in config/auth.php to Backpack.
config/auth.php
'defaults' => [
'guard' => 'backpack',
'passwords' => 'users',
],
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\Models\User::class,
],
],
config/backpack/base.php
'route_prefix' => 'admin',
'setup_auth_routes' => false,
'setup_dashboard_routes' => true,
'setup_my_account_routes' => true,
'user_model_fqn' => App\Models\BackpackUser::class,
'middleware_class' => [
App\Http\Middleware\CheckIfAdmin::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
// \Backpack\Base\app\Http\Middleware\UseBackpackAuthGuardInsteadOfDefaultAuthGuard::class,
],
// Alias for that middleware
'middleware_key' => 'admin',
'authentication_column' => 'email',
'authentication_column_name' => 'Email',
'guard' => 'backpack',
'passwords' => 'backpack',
config/backpack/permissionmanager.php
'models' => [
'user' => App\Models\BackpackUser::class,
'permission' => Backpack\PermissionManager\app\Models\Permission::class,
'role' => Backpack\PermissionManager\app\Models\Role::class,
],
'allow_permission_create' => false,
'allow_permission_update' => false,
'allow_permission_delete' => false,
'allow_role_create' => true,
'allow_role_update' => true,
'allow_role_delete' => true,
'multiple_guards' => true,
app/Models/BackpackUser.php
class BackpackUser extends User
{
use CrudTrait;
use HasRoles;
use InheritsRelationsFromParentModel;
protected $table = 'users';
public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPasswordNotification($token));
}
public function getEmailForPasswordReset()
{
return $this->email;
}
}
So pretty much standard settings. I cannot figure out why the routes are not registered and available. If you get to http://localhost/admin, I get redirected to http://localhost/admin/login, which gives a 404 error. Can anyone help?
You have to enable 'setup_auth_routes' => true in config/base.php. This will allow Backpack to use the standard routes. Then the second step is to use Auth::routes(); inside your routes/web.php
If you are missing some/all of the controllers or UIs then you can scaffold them:
Install laravel/ui part using composer require laravel/ui
Use php artisan ui vue --auth or php artisan ui bootstrap --auth or php artisan ui react --auth depending on what you use for the front-end.

Send Mail Using Lumen

Mail.php
return [
'driver' =>'smtp',
'host' => 'smtp.gmail.com',
//'port' => 587,
'port' =>465,
//'encryption' =>'tls',
'encryption' =>'ssl',
'username' => 'xxxxxxxx#gmail.com',
'password' => 'xxxxxxx',
// 'sendmail' => '/usr/sbin/sendmail -bs',
'sendmail' => '/usr/sbin/sendmail -t',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
];
Controller
$data = []; // Empty array
Mail::send('email.credentials', $data, function($message)
{
$message->to('xxxxxx#gmail.com', 'Jon Doe')->subject('Welcome!');
});
Error
Swift_TransportException Connection could not be established with host
smtp.gmail.com [A connection attempt failed because the connected
party did not properly respond after a period of time, or established
connection failed because connected host has failed to respond.
I Tried...
Change ssl / tls
Change the ports
Add "guzzlehttp/guzzle": "~5.3|~6.0" in composer.json
Add a new line in StreamBuffer.php
$options = array_merge($options, array('ssl' => array('verify_peer' =>
false,'verify_peer_name' => false,'allow_self_signed' => true )));
Please help .
Thank you.
1. Require illuminate/mail
Make sure you’re using the same version as your underlying framework (i.e. if you’re on Lumen v. 5.3, use composer require illuminate/mail "5.3.*").
composer require illuminate/mail "5.5.*"
2. Set up Lumen bootstrap/app.php
First, open your bootstrap.php and uncomment the following lines:
$app->withFacades();
$app->register(App\Providers\AppServiceProvider::class);
Also, add the following line below the last line you uncommented:
$app->configure('services');
This will allow you to define a ‘services’ config file and setup your mail service. Now I know that normally configuration is done in the .env file with Lumen, and we’ll use that shortly, but first we’ll need to write a small config file to map to the .env file.
3. Create your configuration files
Create a new folder at the root level of your install called config(if it doesn’t already exist). In the config folder, create two new files, one named services.php and another named **mail.php**.
In the services.php file paste the following:
<?php
return [
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
];
Lastly, add the following to your .env file:
MAIL_DRIVER=mailgun
MAILGUN_DOMAIN=<your-mailgun-domain>
MAILGUN_SECRET=<your-mailgun-api-key>
Make sure you replace those sneaky placeholders with your actual key and domain. If you’re not using Mailgun, you can always use the other mail providers Mail comes with; have a look at the docs if you plan on using a different provider, they are all easy to set up once you’re at this point.
4. Send Email!
To send an email, use one of the following in your classes (depending on your preference):
use Illuminate\Support\Facades\Mail;
$data = []; // Empty array
Mail::send('email.credentials', $data, function($message)
{
$message->to('xxxxxx#gmail.com', 'Jon Doe')->subject('Welcome!');
});
Finally, don’t forget to read the Laravel Mail docs for more info on how to use this great library.
Have you turned on 2 layers security in your Google account (email address you config in .env file) which uses to send email.

How can I call Artisan::call(...) more than once? (Migrate and then Seed)

I have found that using the Artisan::call() command to migrate and then again to seed results in a proper migration but the database is never seeded. This may be a bug or perhaps there is a way to flush the previous command.
For example:
Artisan::call('migrate', [
'--database' => 'tenant',
'--path' => 'database/tenantMigrations',
'--force' => true,
]);
And then:
Artisan::call('db:seed', [
'--database' => 'tenant',
'--class' => 'TenantSeeder',
]);
As you can see, I am running these commands on a freshly created tenant DB to "provision" it. Each of these commands works separately, but not together.
I have tried looking for further documentation on joining the two commands while being able to specify the class of the seeder. This would potentially look like:
Artisan::call('migrate', [
'--database' => 'tenant',
'--path' => 'database/tenantMigrations',
'--force' => true,
'--seed' => true,
'--class' => 'TenantSeeder', // this is the only one I can't do, which is critical
]);
I have also tried running the seeder like:
(new \TenantSeeder)->run();
I get the error: Call to a member function line() on null.
It is also interesting to note that all works properly on my local Homestead environment, but not on a Digital Ocean server managed by Forge.
Edit
My current solution is to put my seeder logic inside of regular classes (that do not extend the base Seeder class) and call these as I displayed above.
You can create a wrapper command with all the options needed, then call the migrate, seed, etc commands individually:
php artisan make:command MigrateAndSeedCommand
The class may look something like:
class MigrateAndSeedCommand extends Command
{
protected $signature = 'migrateandseed {--database=} {--path=} {--force} {--seed} {--class=}';
public function handle()
{
Artisan::call('migrate', [
'--database' => $this->option('database'),
'--path' => $this->option('path'),
'--force' => $this->option('force'),
]);
Artisan::call('db:seed', [
'--database' => $this->option('database'),
'--class' => $this->option('class'),
]);
}
}
Usable via:
php artisan migrateandseed --database=tenants --path=database/tenantMigrations --force --seed --class=TenantSeeder
// or
Artisan::call('migrateandseed', [
'--database' => 'tenant',
'--path' => 'database/tenantMigrations',
'--force' => true,
'--seed' => true,
'--class' => 'TenantSeeder',
]);
EDIT
Use $this instead of Artisan, as well as optionally queueing the commands:
// or $this->queue
$this->call('db:seed', [
'--database' => $this->option('database'),
'--class' => $this->option('class'),
]);
Calling Commands From Other Commands

Dusk not working with factories and/or migrations in Homestead

Using a fresh install of Laravel and dusk, then copying the exact test from the docs for logging in the user, I get an error that the users table doesn't exist.
I don't get any error when using a factory to create a user, but when trying to login as that user, i can see the browser window opening (screenshoots), typing in the creds, then seeing the error that user can't be found.
I see that Dusk tests never ran the migrations.
I change my config/database.php and .env.dusk.local
// config/database.php
'connections' => [
'testing' => [
'driver' => 'sqlite',
'database' => database_path('testing.sqlite'),
'prefix' => '',
],
],
`// .env.dusk.local
APP_URL=http://project.dev
APP_ENV=testing
DB_CONNECTION=testing`
and ran composer update but the error persist :( my test code:
public function setUp() {
parent::SetUp();
factory(Rol::class)->create(['nombre' => 'Administrador']);
$this->usuario = factory(Usuario::class)->create(['email' => 'correo#ejemplo.com', 'password' => bcrypt('123456'), 'rol_id' => Rol::where('nombre', 'Administrador')->first()->id]);
}
/**
* #tests
*/
public function loggeo_usuario() {
$this->browse(function (Browser $browser) {
$browser->visit(route('login'))
->assertSee('Correo')
->type('email', $this->usuario->email)
->type('#password', '123456')
->click('#login-button')
->assertSee('Ayuda');
});
}

How to send Log event from Laravel to Loggly?

I want to send Monolog logs from my Laravel 5.1 application to Loggly.com online log management service. From all possible environment, including local development.
I have found some outdated libs and complicated ways to do this. So I ended up with very simple solution. Actually, Laravel Monolog Handler already have Loggly Handler out of the box.
Add config info to config/services.php:
'loggly' => array(
'key' => 'ENTER_YOUR_LOGGLY_TOKEN_HERE',
'tag' => 'ProjectName_' .strtolower(env('APP_ENV')),
),
Than add Monolog handler in bootstrap/app.php, before $app is returned:
/*
|--------------------------------------------------------------------------
| Setup Loggly Handler
|--------------------------------------------------------------------------
*/
$app->configureMonologUsing(function($monolog) {
$handler = new \Monolog\Handler\LogglyHandler(config('services.loggly.key'),\Monolog\Logger::DEBUG);
$handler->setTag(config('services.loggly.tag'));
$monolog->pushHandler($handler);
});
Voila! You are getting your Monolog Logs in Loggly dashboard.
UPDATE: (thanks #thitami)
Based on laravel.com/docs/5.6/upgrade
The configureMonologUsing Method
If you were using the configureMonologUsing method to customize the Monolog instance for your application, you should now create a custom Log channel. For more information on how to create custom channels, check out the full logging documentation.
I was able to manage having Laravel's default local log behaviour, and pushing to Loggly in the same time, by tweaking mladen-janjetovic's code a bit. Tested on Laravel 5.3
config/services.php:
'loggly' => [
'key' => 'ENTER_YOUR_LOGGLY_TOKEN_HERE',
'tag' => 'ProjectName_' .strtolower(env('APP_ENV')),
],
bootstrap/app.php:
/*
|--------------------------------------------------------------------------
| Push to Loggly, and save locally.
|--------------------------------------------------------------------------
*/
$app->configureMonologUsing(function($monolog) use ($app) {
$log = $app->make(Illuminate\Log\Writer::class);
$logglyHandler = new \Monolog\Handler\LogglyHandler(config('services.loggly.key'));
$logglyHandler->setTag(config('services.loggly.tag'));
if (config('app.env') == 'production')
{
// Push to Loggly and save local if in production
$log->getMonolog()->pushHandler($logglyHandler);
$log->useFiles(storage_path('/logs/laravel.log'));
}
else
{
// Otherwise, save only locally
$log->useFiles(storage_path('/logs/laravel.log'));
}
});
Alternatively, you may use Monolog-Cascade to do this.
Monolog-Cascade is a Monolog extension that allows you to set up and configure multiple loggers and handlers from a single config file.
Here is a sample config file for Monolog-Cascade using Loggly. This would log to you stdOut and to Loggly:
---
handlers:
console:
class: Monolog\Handler\StreamHandler
level: DEBUG
stream: php://stdout
error_loggly_handler:
class: Monolog\Handler\LogglyHandler
level: ERROR
token: xxxx-xxxx-xxxxxxxx
tags: [cascade, waterfall]
loggers:
my_logger:
handlers: [console, error_loggly_handler]
If you're interested, here is a blog post on Cascade => https://medium.com/orchard-technology/enhancing-monolog-699efff1051d
[Disclaimer]: I am the main contributor of Monolog-Cascade.
Got mine working with little configuration with Laravel 8.
Just use the built-in monolog handler for Loggly.
Edit your app/config/logging.php
use Monolog\Handler\LogglyHandler;
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'loggly'],
'ignore_exceptions' => false,
],
'loggly' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => LogglyHandler::class,
'with' => [
'token' => env('LOGGLY_TOKEN'),
],
],
]
For more advanced logging (for my case I need to set the tag as it was missing in the built-in handler's constructor.
Copy the built-in handler where you can find it within vendor folder
(e.g: vendor/monolog/monolog/src/Monolog/Handler/LogglyHandler.php) into your app folder of choice (e.g: app/Logging/CustomLogglyHandler.php).
Modify the constructor to set the tags, and you need to change some of the imports as we're on different namespaces.
// app/Logging/CustomLogglyHandler.php
namespace App\Logging;
use Monolog\Handler\AbstractProcessingHandler;
use Monolog\Handler\MissingExtensionException;
use Monolog\Logger;
use Monolog\Formatter\FormatterInterface;
use Monolog\Formatter\LogglyFormatter;
use function array_key_exists;
use CurlHandle;
use Monolog\Handler\Curl\Util as CurlUtil;
public function __construct(string $token, array|string $tag = [], $level = Logger::DEBUG, bool $bubble = true)
{
if (!extension_loaded('curl')) {
throw new MissingExtensionException('The curl extension is needed to use the LogglyHandler');
}
$this->token = $token;
if (is_array($tag)) {
$this->tag = $tag;
} else {
$this->tag = [$tag];
}
parent::__construct($level, $bubble);
}
// config/logging.php
'loggly' => [
'driver' => 'monolog',
'level' => env('LOG_LEVEL', 'debug'),
'handler' => CustomLogglyHandler::class,
'with' => [
'token' => env('LOGGLY_TOKEN'),
'tag' => strtolower(env('APP_NAME', 'Laravel')) . '_' . strtolower(env('APP_ENV', 'production'))
],
],
To expand on Hassan's contribution (posting as an answer, as I still don't have enough reputation to post a comment).
If you have a need to use daily logs locally, you could use following code:
$logFile = 'laravel'.'.txt';
$log->useDailyFiles(storage_path().'/logs/'.$logFile);
Of course, logfile name is totally arbitrary. In this example, format will be as such:
laravel-YYYY-MM-DD.txt
Edit:
with an upgrade to 5.4 this line does not work anymore:
$log = $app->make(Illuminate\Log\Writer::class);
As a workaround, you can create Writer instance manually, injecting $monolog available from configureMonologUsing closure:
$log = new Illuminate\Log\Writer($monolog);

Resources