laravel-acl icon indicating copy to clipboard operation
laravel-acl copied to clipboard

Assign Permission function cannot be found on Role Model

Open DamPe88 opened this issue 8 years ago • 3 comments
trafficstars

When trying the module on Laravel 5.4 and when allocating permission to the selected Role, assignPermission is not found.following your wiki on this.

$permUser  = Permission::find(1);
$roleAdmin = Role::first();
$roleAdmin->assignPermission($permUser);

no errors, but couldn't find details on the database table. When i look at the model, assignPermission function is not there.could you please let me know why.am i doing anything wrong here?

Thanks Dami

DamPe88 avatar Apr 26 '17 10:04 DamPe88

I have the same problem. I got an error "Method assignPermission does not exist." and I check on the Role class and there isn't a method with that name.

moransk8 avatar Oct 30 '17 03:10 moransk8

@DamPe88 @moransk8 i'll take a look. meanwhile if you found a fix, please post a PR. Thanks

kodeine avatar Oct 30 '17 04:10 kodeine

@kodeine The problem was that I was using the method get() instead of first() when instantiating the role and this get you back an array so I changed it to first() and it works great. eg: $roleAdmin = Role::where('name', '=', 'Admin')->get(); // here you can't call the method to assign permission $roleAdmin = Role::where('name', '=', 'Admin')->first(); // I changed to first() and works great

moransk8 avatar Oct 30 '17 05:10 moransk8