kevinwakhisi's avatar

Spatie Permissions

I wanted to have a standard way of naming my permissions and it got me thinking about how I would make this possible. Let's say I have a single input (user) and on save, I generate four permissions namely : Create Users, Read Users, Update Users and Delete Users. How can this be made possible?

0 likes
5 replies
Sinnbeck's avatar

Do you mean you want to attach those permissions to the user?

$user->givePermissionTo(['Create Users', 'Read Users', 'Update Users', 'Delete Users']);
kevinwakhisi's avatar

@Sinnbeck Not really but on creating permission let's say input(Content ) as the only input in my form field, there are four inputs generated rather saved in the database as (create content, read content, Update content and delete content)

Snapey's avatar

@kevinwakhisi it's up to you to decide how granular you need it in this application

quite often i will just have eg users.read and users.edit only, with create update and delete all being possible with edit

kevinwakhisi's avatar

@Snapey probably I never explained myself quite well. My question was how can I magically make more out of one input. I am creating a user permission, and the permissions as you have said it, user. read and user.edit, but when creating permissions I wanted to have one input then the CRUD name becomes the suffix or prefix of the input

Snapey's avatar

@kevinwakhisi i guess i'm not understanding how you can have a permissions name gathered in an input field to then be used in code?

in my apps, permissions are hard coded into the application with roles able to be created by users and assigned to users and containing a selection of predefined permissions

Please or to participate in this conversation.