Open dokicro opened 8 years ago
I don't know, if this works, but it should give you an idea how to make a trait yourself and add it to your user model. Me myself prefer the way using helper functions:
if (! function_exists('attachPermissionFromSlug')) {
/**
* app/Support/helpers.php
*
* Get a permission by slug and attach it.
*
* @param App\User $user
* @param string $slug
*
* @return bool true when succeed
*/
function attachPermissionFromSLug(\App\User $user, $slug)
{
$permission = Permission::where('slug', $slug)->first();
if (! is_null($permission)) {
$user->attachPermission($permission);
return true;
}
return false;
}
}
Hi,
I would be cool to add feature to allow attachPermission('slug').
Thanks!