Pass Paremeter to Middleware 传递变量

我只能说这种方式实在太神奇,居然是用冒号连接。

    public function __construct(){

        $path='manage/user';
        $this->middleware('CheckUserGroup:'.$path);

    }
    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.');
        }
    }

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.