<?php

namespace App\Http\Middleware;
use Closure;

class LoginMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if($request->session()->has('username')){
            //判断用户的权限
            $action=$request->route()->getActionMethod();
            $actions=explode('\\', \Route::current()->getActionName());
            $modelName=$actions[count($actions)-2]=='Controllers'?null:$actions[count($actions)-2];
            $func=explode('@', $actions[count($actions)-1]);
            //获取的控制器名字
            $controller=$func[0];
            $actionName=$func[1];
             //获取当前登录用户的权限列表
             $nodelist = session('nodelist');
             //进行对比
            //  if(empty($nodelist[$controller]) || !in_array($action,$nodelist[$controller])){
                 
            //      return redirect("/admin/index")->with('access','抱歉,你的权限不足,请联系超级管理员');
            //  }
            return $next($request);
        }else{
            return redirect('/admin/hehe/haha/login');
        }
    }
}
