You can register your middleware inside your module service provider using this->middleware() method. Or add it in the Kernel.php of the app/Http directory.
Could you provide me the sample please?
@nWidart that no longer works, you must use ->aliasMiddleware()
Call to undefined method Modules\Vproducts\Providers\VproductsServiceProvider::middleware()
In case anyone is still confused, in your module's service provider's boot method, add register your middleware thus
app()->make('router')->aliasMiddleware('auth2', \Your\Namespace\Class\Auth2::class);
This assumes you are trying to create a middleware called auth2. Then you can use it on your controllers or routes like:
Route::middleware('auth2') ....
$this->middleware('auth2') ....
Find module service provider file under Module->Providers->ModuleServiceProvider.php, Append middleware in boot method.
Exa.
InstallerServiceProvider.php
public function boot(Illuminate\Routing\Router $router)
{
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'Database/Migrations'));
// solution 1
$router->middlewareGroup('update', [\Modules\Installer\Http\Middleware\CanUpdate::class]);
// solution 2
app()->make('router')->aliasMiddleware('update', \Modules\Installer\Http\Middleware\CanUpdate::class);
}
This work fine!
Most helpful comment
In case anyone is still confused, in your module's service provider's boot method, add register your middleware thus
app()->make('router')->aliasMiddleware('auth2', \Your\Namespace\Class\Auth2::class);This assumes you are trying to create a middleware called auth2. Then you can use it on your controllers or routes like:
Route::middleware('auth2') ....$this->middleware('auth2') ....