Pass Paremeter to Middleware 传递变量
我只能说这种方式实在太神奇,居然是用冒号连接。
1 2 3 4 5 6 |
public function __construct(){ $path='manage/user'; $this->middleware('CheckUserGroup:'.$path); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
public function handle($request, Closure $next, $path) { $permit = false; if (Auth::user()) { $user_class = Auth::user()->user_class(); $sidebar=Sidebar::where('url',$path)->first(); if ($user_class>=$sidebar->visible){ $permit=true; } } if($permit==true){ return $next($request); }else{ return redirect('/')->withErrors('Sorry, you\'re not authorized to visit that page.'); } } |