如何在 1 条路线上使用 2 个角色?
How you can use 2 roles on 1 route?
请告诉我如何在 1 条路线上使用 2 个角色。我正在使用 Laravel 权限。
路线
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']);
});
是的,但你也可以做,请更改中间件。
Route::group(['middleware' => ['auth','web','roles'],'roles'=>['admin','driver']],function() {
});
用|
分隔。
Route::group(['middleware'=>['role:admin|user']],function(){
来源:https://spatie.be/docs/laravel-permission/v4/basic-usage/middleware
引用:Alternatively, you can separate multiple roles or permission with a | (pipe) character:
作为文档 says
you can separate multiple roles or permission with a | (pipe) character:
Route::group(['middleware' => ['role:super-admin|writer']], function () {
//
});
请告诉我如何在 1 条路线上使用 2 个角色。我正在使用 Laravel 权限。
路线
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']);
});
是的,但你也可以做,请更改中间件。
Route::group(['middleware' => ['auth','web','roles'],'roles'=>['admin','driver']],function() {
});
用|
分隔。
Route::group(['middleware'=>['role:admin|user']],function(){
来源:https://spatie.be/docs/laravel-permission/v4/basic-usage/middleware
引用:Alternatively, you can separate multiple roles or permission with a | (pipe) character:
作为文档 says
you can separate multiple roles or permission with a | (pipe) character:
Route::group(['middleware' => ['role:super-admin|writer']], function () {
//
});