trzew
trzew

Reputation: 445

Problem with configuration of routing with guard in Laravel

I am beginner php developer. I have small problem with routing. I use this component on my website: spatie/laravel-permission

and I have this route:

Route::group(['prefix' => '', 'middleware' => ['role:superadmin, admin, seller, telemarketer']], function () {
    Route::get('/', 'HomeController@index')->name('cms.home');

    Route::resource('pages', 'PageController')->only(['index', 'create', 'store', 'edit', 'update', 'destroy']);
    Route::get('/pages/dataTable', 'PageController@dataTable')->name('pages.dataTable');
});

I have problem with middleware. When I have this: ['role:superadmin, admin, seller, telemarketer']] I have error: InvalidArgumentException Auth guard [ admin] is not defined.

My user has 'superadmin' role.

When I make this code: ['role:superadmin']] - it's work fine.

How can I repair it to other my role??

Please help me

Upvotes: 0

Views: 393

Answers (1)

lagbox
lagbox

Reputation: 50491

If you are using the role middleware from that package, it does not take a list or roles as the middleware parameters. The first parameter is the role, the second is the guard to use.

public function handle($request, Closure $next, $role, $guard = null)

If you want to pass an array of roles you can use the | to distinguish between them:

role:superadmin|admin|seller|telemarketer

That is all one parameter being passed and the middleware will break that up into an array of roles.

Upvotes: 2

Related Questions