roles icon indicating copy to clipboard operation
roles copied to clipboard

AttachPermission with slug.

Open dokicro opened this issue 8 years ago • 1 comments

Hi,

I would be cool to add feature to allow attachPermission('slug').

Thanks!

dokicro avatar Mar 07 '16 16:03 dokicro

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;
    }
}

Isfirs avatar Apr 08 '16 11:04 Isfirs