0

in my project , i want to pass 'user_id' to filter to check.

this is isAdmin function:

public function isAdmin($id){
    $user=User::find($id);
    if($user->role==10){
        return true;
    }
    return false;
}

and this is my route file:

Route::group(array('before'=>'admin'),function(){
    Route::get('dashboard','UserController@Dashboard');
});

this is my filte that iwant give user_id ($id), and idont know how.

Route::filter('admin',function($id)
{
    if(Auth::guest() or ! Auth::user()->isAdmin($id))
        return Redirect::guest('user/logout');

});
AmirAgha
  • 135
  • 2
  • 6

1 Answers1

0

For this case, you can directly check from the filter like this:

Route::filter('admin',function()
{
    if(Auth::guest() or Auth::user()->role != 10)
        return Redirect::guest('user/logout');
});

You do not need to pass params.

Also have a look to this link if you really want to pass params.

Link of Laravel Doc: here

Community
  • 1
  • 1
Anindya Dhruba
  • 500
  • 7
  • 21