Laravel-permission: Bug Guard.php

Created on 30 Jul 2019  路  4Comments  路  Source: spatie/laravel-permission

The $default value is never returned

public static function getDefaultName($class): string
    {
        $default = config('auth.defaults.guard');

        return static::getNames($class)->first() ?: $default;
    }
wontfix

Most helpful comment

Workaround: put the guard you want as the first item in the 'guards' array.

'guards' => [
        /**
         * Workaround: put the guard you want as the first item in the 'guards' array
         * @see Spatie\Permission\Guard#getDefaultName
         */
        'backpack' => [
            "driver" => "session",
            "provider" => "backpack"
        ],
        'web' => [ .....

All 4 comments

same here, I am using version 2.37.0

I can't assign roles to a selected user with the same guards.

    return static::getNames($class)->first() ?: $default;

This is by design in v2.
Changing it in v2 will break existing installations.
There are plans to remove the guard complexity in a future version.

Workaround: put the guard you want as the first item in the 'guards' array.

'guards' => [
        /**
         * Workaround: put the guard you want as the first item in the 'guards' array
         * @see Spatie\Permission\Guard#getDefaultName
         */
        'backpack' => [
            "driver" => "session",
            "provider" => "backpack"
        ],
        'web' => [ .....

thanks man.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vpratfr picture vpratfr  路  4Comments

MichalKrakow picture MichalKrakow  路  4Comments

feliperoan picture feliperoan  路  3Comments

enghelewa picture enghelewa  路  4Comments

hosseinnedaei picture hosseinnedaei  路  3Comments