2017-04-17 83 views
0

我試圖在Laravel 5.4中創建一個acl。在5.2它使用這樣的工作,但5.4是不喜歡這個了,它給此錯誤消息:AuthServiceProvider.php中的ErrorException Laravel 5.4中的未定義變量

ErrorException在AuthServiceProvider.php未定義的變量:門

任何人都可以解釋爲什麼它不工作,以及如何要解決這個問題? 這裏是我的代碼:

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; 

    }); 

} 
+0

'$ gate'不被任何定義?很高興看到它的定義。 –

+0

它在這裏被定義,還是我做錯了? $ gate-> define('auth',function($ user,$ role = NULL) – Geisiane

回答

0

使用門的門面,增加use Gate;和更改

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

Gate->define('auth', function($user, $role=NULL) 
相關問題