Answer the question
In order to leave comments, you need to log in
How to use two roles in middleware?
Hello!
Laravel 8.
There are roles in the project and the roles have middleware:
...
public function handle($request, Closure $next, ... $roles)
{
dd($roles);
...
Route::get('/page', [PageController::class, 'index'])->name('page')->middleware('role:admin,manager');
Answer the question
In order to leave comments, you need to log in
I realized that there are no simple solutions, there are only crutches:
1 Method, use several parameters:
in the route:
Route::get('/page', [PageController::class, 'index'])->name('page')->middleware('role:admin,manager');
...
public function handle($request, Closure $next, $role1, $role2)
{
//Используем уже здесь $role1, $role2
...
Route::get('/page', [PageController::class, 'index'])->name('page')->middleware('role:admin|manager');
...
public function handle($request, Closure $next, $role)
{
if (!is_array($role)) {
$roles = explode('|', $role);
}
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question