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

TheRabber's avatar

Spatie permissions auditable in Filament

I hope this is the right channel for it.

I'm currently implementing spatie permissions and laravel-auditing whilst using Filament with filament-shield. I can assign and create permissions and roles without any problems, but trying to audit the assignment of them is not working the way I'd like to have it work, as they're not showing up in the logs. So I added a custom action which uses the ->syncAudit() functionality from laravel-auditing, which works as expected, but creates a new button. I tried to add the same functionality via custom save procedure on the UserResource, which is getting called, but misses the roles in the payload, I guess they will be saved on the RolesResource functionality. As filament-shield is providing it's own resource here, I'm not sure if I should create my own one and how to properly bind that.

Last thing is that spatie permissions has its own sync methods, like syncPermissions, which in the end call the attach() and detach() methods of eloquent. Is the a way to intercept here and replace these calls with attachAuditable() and detachAuditable()? Problem is probably that you have to give the relation name as well...

As a dirty fix I created the pivot models and put audit onto them

Thanks for any input!

0 likes
0 replies

Please or to participate in this conversation.