How to pass multiple parameters to middleware with OR condition in Laravel 5.2

后端 未结 6 1545
误落风尘
误落风尘 2020-12-06 00:48

I am trying to set permission to access an action to two different user roles Admin, Normal_User as shown below.

Route::group([\'middleware\' => [\'role_c         


        
6条回答
  •  孤城傲影
    2020-12-06 01:11

    To add multiple parameters, you need to seperate them with a comma:

    Route::group(['middleware' => ['role_check:Normal_User,Admin']], function() {
            Route::get('/user/{user_id}', array('uses' => 'UserController@showUserDashboard', 'as' => 'showUserDashboard'));
        });
    

    Then you have access them to in your middleware like so:

    public function handle($request, Closure $next, $role1, $role2) {..}
    

    The logic from there is up to you to implement, there is no automatic way to say "OR".

提交回复
热议问题