路由中间件验证

时间:2016-05-12 20:43:05

标签: php laravel

我的路线是:

Route::get('/{slug}',['as' => 'index', 'middleware' => 'player_group', 'uses' => 'PlayerController@index']);

我要做的是检查经过身份验证的用户是否在{slug}组。

public function handle($request, Closure $next)
{
    $user = Auth::user()->id;
    $user_grupo = DB::select( DB::raw("SELECT id FROM user JOIN group ON group.id_ = user.id_group WHERE user.id = ".$user." AND group.slug = '".$slug."'") );;
    if (!$user_group) {
       //ERROR 
    } else { 
       return $next($request); 
    }
}

但那不起作用......这是一个错误:

Undefined variable: slug

1 个答案:

答案 0 :(得分:1)

从路线使用$request->route('slug');

获取参数