Search code examples
laravelroleslaravel-permission

How you can use 2 roles on 1 route?


Please tell me how you can use 2 roles on 1 route. I am using the Laravel Permission.

Routes

Route::group(['middleware' => ['role:user_сitisen']], function () {
    Route::get('/addcitisens', [App\Http\Controllers\CitisenControl::class, 'index']);
    Route::get('/citisen/{id}', [App\Http\Controllers\CitisenControl::class, 'show']);
    Route::post('/citisen/{id}', [App\Http\Controllers\CitisenControl::class, 'update'])->name('citisen');
    Route::get('/destroy/{id}', [App\Http\Controllers\CitisenControl::class, 'destroy']);
    Route::post('/citisens', [App\Http\Controllers\CitisenControl::class, 'store']);
    Route::get('/citisens/export', [App\Http\Controllers\CitisenControl::class, 'CitisenExport']);
});

Route::group(['middleware' => ['role:user_avto']], function () {
    Route::get('/avtoslist', [App\Http\Controllers\AvtosController::class, 'index']);
    Route::get('/addavtos', [App\Http\Controllers\AvtosController::class, 'indexAdd']);
    Route::post('/avtos', [App\Http\Controllers\AvtosController::class, 'store']);
});

Route::group(['middleware' => ['role:admin']], function () {
    Route::get('/addcitisens', [App\Http\Controllers\CitisenControl::class, 'index']);
    Route::get('/citisen/{id}', [App\Http\Controllers\CitisenControl::class, 'show']);
    Route::post('/citisen/{id}', [App\Http\Controllers\CitisenControl::class, 'update'])->name('citisen');
    Route::get('/destroy/{id}', [App\Http\Controllers\CitisenControl::class, 'destroy']);
    Route::post('/citisens', [App\Http\Controllers\CitisenControl::class, 'store']);
    Route::get('/citisens/export', [App\Http\Controllers\CitisenControl::class, 'CitisenExport']);
    Route::get('/avtoslist', [App\Http\Controllers\AvtosController::class, 'index']);
    Route::get('/addavtos', [App\Http\Controllers\AvtosController::class, 'indexAdd']);
    Route::post('/avtos', [App\Http\Controllers\AvtosController::class, 'store']);
    Route::get('/usersList', [App\Http\Controllers\UsersController::class, 'index'])->name('usersList');
    Route::get('/addusers', [App\Http\Controllers\UsersController::class, 'indexUser']);
    Route::post('/users', [App\Http\Controllers\UsersController::class, 'store']);
    Route::get('/users/{id}', [App\Http\Controllers\UsersController::class, 'show']);
    Route::post('/users/{id}', [App\Http\Controllers\UsersController::class, 'update']);
    Route::get('/destroyuser/{id}', [App\Http\Controllers\UsersController::class, 'destroy']);
});

Solution

  • As documentation says

    you can separate multiple roles or permission with a | (pipe) character:

    Route::group(['middleware' => ['role:super-admin|writer']], function () {
        //
    });