AuthServiceProvider.php 中的 ErrorException Laravel 5.4 中的未定义变量

ErrorException in AuthServiceProvider.php Undefined variable in Laravel 5.4

我正在尝试在 Laravel 5.4 中创建 acl。在 5.2 上它曾经是这样工作的,但是 5.4 不再是这样了,它给出了这个错误信息:

AuthServiceProvider.php 中的 ErrorException 未定义 variable:gate

谁能解释为什么它不起作用以及如何解决它? 这是我的代码:

 public function boot()
{
    $this->registerPolicies();

    $gate->define('auth', function($user, $role=NULL){
        if($role === NULL){
            $actions = Route::current()->getAction();

            if(! isset($actions['role']))
                return false;
            $role = $actions['role'];
        }
        $objRole = new Role();
        $roles = $objRole->roles($user->id);
        if(in_array($role, $roles))
            return true;
        return false;

    });

}

使用Gate作为门面,添加use Gate;并更改

$gate->define('auth', function($user, $role=NULL)

Gate->define('auth', function($user, $role=NULL)