Skip to content

🐛 Permissions mutator should not try to save the role #22

@andrzejkupczyk

Description

@andrzejkupczyk

Since the setPermissionsAttribute() mutator tries to save the model, it is not possible to create a new role along with permissions using the create method ("Integrity constraint violation: 1062 Duplicate entry"). In my opinion mutators are not meant to communicate with database at all.

This is an example of code that does not work:

Role::create([
    'name' => 'Administrator',
    'slug' => 'admin',
    'permissions' => [
        'viewNova',
    ],
]);

There are at least two solutions. You could resign from saving the model within the mutator or guard "permissions" attribute (disable mass assignment).

Great package btw. Thank you 🏅

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions