我的路线是:
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
答案 0 :(得分:1)
从路线使用$request->route('slug');