Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andrzejkupczyk opened this issue Jul 2, 2020 · 0 comments
Open

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

andrzejkupczyk opened this issue Jul 2, 2020 · 0 comments

Comments

@andrzejkupczyk
Copy link

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 🏅

@andrzejkupczyk andrzejkupczyk changed the title 🐛 Permissions mutator should not try to save the role 🐛 Permissions mutator should not try to save the role Jul 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant