Assign Permission function cannot be found on Role Model
DamPe88 opened this issue · 3 comments
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
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.
@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