0

I'm trying to multiple 'can' Middlewares with route groups in laravel 5.4 like bellow,

Route::group(['middleware' => 'can:director,super'], function() {
  Route::get('/customerDetails', 'CustomerController@index');
});

but it only work for first middleware in the list, and also try this method and its not working with any 'can' middleware

Route::middleware(['can:super', 'can:director'])->group(function () {
  Route::get('/customerDetails', 'CustomerController@index');
});

How can I use multiple 'can' middleware correctly with route groups?

Udara Herath
  • 805
  • 2
  • 18
  • 37

2 Answers2

0

Try using the or "||" operator.

Route::middleware(['can:super' || 'can:director'])->group(function () {
  Route::get('/customerDetails', 'CustomerController@index');
});

" | " will check every part of condition while " || " will check in sequence starting from first. If any condition in sequence is found to be true then || stops further checking. so || is more efficient in conditional statements

0

Route::name('admin.')->prefix('admin')->middleware('auth', 'admin')->group(function () {

}