Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dpakagarwal's avatar

create permission based on model or migration

hello, every laravel developer right now I m working on a project and implementing spatie user, roles, and permission package eagerly. I want to auto-create permission ('create', 'update', 'show', 'delete') for each table when we migrate all tables to database. it is possible to do this kind of feature so that the admin can get all permission automatically and not every time create permission for each table respectively.

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

If the admin gets all permissions automatically, then you can use a before Gate

https://spatie.be/docs/laravel-permission/v5/basic-usage/new-app#content-grant-super-admin-access

Otherwise; check the command classes e.g. MigrateCommand, FreshCommand to see what events are dispatched whenever migrations are executed (e.g. there is a SchemaLoaded event; a DatabaseRefreshed event) - you can create your own listener(s) to interrogate the Database schema and generate the CRUD permissions per table.

dpakagarwal's avatar

@tykus thanks for your reply, but I am the intermediate level guy in laravel , and I had not used or listen to any such types of this events, so can you help me to resolve this

Please or to participate in this conversation.