mercredi 22 mai 2019

Laravel set config values using middlware

In my laravel package, i want to set new config values using Global Middlware

So, i register middleware using service provider

public function boot()
    {
        Route::middlewareGroup('mypackagename', config('mypackagename.middleware', []));
        .....

Then i set the middleware class in the package config file like this:

'middleware' => [
        'web',
        qoraiche\mypackagename\Http\Middleware\setConfigs::class,
    ],

Middleware:

public function handle($request, Closure $next)
    {
        // --
        config(['mail.from.name' => 'New Name']);

        return $next($request);
    }

I do tests and the middleware registered correctly, but I still can't set config values in runtime.

the only thing that works for me is when i set config values in the service provider boot method.

public function boot()
    {

     config(['mail.from.name' => 'New Name']);

     ....

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire