Instead of
'middleware' => 'auth', 'middleware' => ['role:role1']
use this
'middleware' => ['auth', 'role:role1']
Or
->middleware('auth', 'role:role1')
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi All, pretty new to laravel, please do help. I understand its best practice to follow the resource controllers format, however, for some reason the existing setup has too many functions (large project) that's not properly arranged in resource controllers format. How to handle the Roles & Permissions if I would like to provide specific permission to a user?
Also, can the following routes be used for permissions? or is that essential to have Route::resource only?
Route::any('XXX','Yyy@zzz');
Example:
Role 1 has access to view
Role2 has access to view and Edit
Route::group(['middleware' => 'auth', 'middleware' => ['role:role1'], 'namespace' => 'role1'], function () {
Route::any('list', 'MyController@list');
});
Route::group(['middleware' => 'auth', 'middleware' => ['role:role2'], 'namespace' => 'role2'], function () {
Route::any('list', 'MyController@list');
Route::any('edit/{$id}', 'MyController@edit');
});
Can someone please suggest & help?
Just add it to that route (just an example)
Route::any('list', 'MyController@list')->middleware('role:role1');
Please or to participate in this conversation.