Zizaco / entrust

Role-based Permissions for Laravel 5
MIT License
6.05k stars 1.29k forks source link

Controller Middleware (Permissions) #421

Open psaunders opened 8 years ago

psaunders commented 8 years ago

This controller constructor code works, no problem and handy for a Laravel Resource Constructor

public function __construct(){
        $this->middleware('role:administrator|writer', ['except' => ['index','show']]);
}

This gives you an error

public function __construct(){
        $this->middleware('permission:create-article', ['only' => ['create','store']]);
}

ErrorException in Gate.php line 321: Illegal offset type in isset or empty. The $ability var is an array when passed from the controller, but a string when passed from routes.php.

mediabeastnz commented 8 years ago

Bump.. getting the same error since updating to 5.3

finalblast commented 7 years ago

Same issue.

swaylay commented 7 years ago

Anyone have a solution yet?

freel132 commented 7 years ago

Update your user model:

use Zizaco\Entrust\Traits\EntrustUserTrait;

and

use EntrustUserTrait;
BrunoNicholas commented 4 years ago

This issue is solved, The code above is correct ans the updated user model as well.