0

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

1
  • Try removing the spaces. ['role:superadmin,admin,seller,telemarketer'] Commented Oct 19, 2020 at 21:06

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.