Skip to content

[Bug]: Guard not being passed to permissions during sync #23

@craigrileyuk

Description

@craigrileyuk

What happened?

As of v1.5, If you have a role with a guard other than 'web', the permissions created through that role are still given the guard of 'web'.

This issue isn't present in v1.4.

class AuditorRole extends DefinedRole
{
    /** @var array|string[]  */
    protected array $guards = [
        'admin'
    ];

    /**
     * List of enumerated permissions for the `admin` guard
     *
     * @return array
     */
    public function admin(): array
    {
        return [
            ...AuditAbility::cases()
        ];
    }
}

will create all permissions in the database with 'guard_name' of 'web' still. Then it errors during the 'SyncDefinedRoles' job because the permission with the guard_name of 'admin' doesn't exist.

How to reproduce the bug

Create a role without a web guard, and set it permissions.

Run the rbac:reset command.

Package Version

1.5.0

PHP Version

8.4.12

Laravel Version

12.31.1

Which operating systems does with happen with?

Linux

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions