Middleware parameters and packages

- 1 answer

Ad

I have a route defined as

Route::get('/test', 'Package\Namespace\Controllers\[email protected]')
    ->name('index-test')
    ->middleware(['Package\Namespace\Middleware\TestMiddleware']);

I want to call another middleware keeping the syntax (->middleware(...)). I have looked at the docs but I cannot figure out how to do this using the above syntax and namespaced middleware (I am developing a package)

Ad

Answer

Ad

its just array:

Route::get('/test', 'Package\Namespace\Controllers\[email protected]')
    ->name('index-test')
    ->middleware(['Package\Namespace\Middleware\TestMiddleware','Package\Namespace\Middleware\TestMiddleware2','Package\Namespace\Middleware\TestMiddleware3']);

to pass parameters to middleware: Middleware parameters may be specified when defining the route by separating the middleware name and parameters with a :. Multiple parameters should be delimited by commas:

Route::get('/test', 'Package\Namespace\Controllers\[email protected]')
    ->name('index-test')
    ->middleware(['Package\Namespace\Middleware\TestMiddleware:parameter','Package\Namespace\Middleware\TestMiddleware2:parameter','Package\Namespace\Middleware\TestMiddleware3:parameter']);
Ad
source: stackoverflow.com
Ad