add column id of pivot record in relations#619
add column id of pivot record in relations#619gpibarra wants to merge 1 commit intoJosephSilber:masterfrom
Conversation
|
Hmmm. I'm afraid this is a breaking change. The The only reason I'm maybe still considering it is that version 1.0 had the On the other hand, we never told users that they must add those columns, so people that had been running Bouncer prior to 1.0 are now using 1.0 as intended, but will have it break in production. That's kinda unacceptable. 🤔 |
|
Thanks for the reply. |
|
@JosephSilber With the update to Laravel11, would it be a good time for this? |
|
The Laravel 11 update is not a breaking change. See the release notes: https://github.com/JosephSilber/bouncer/releases/tag/v1.0.2 |
I am working with this package and I wanted to have audit processes, I need to know the id of the records created in the
assigned_rolesandpermissionspivot tables. Particularly I am using the package https://github.com/spatie/laravel-activitylog, but it is not important since the pivot relationships are not with models which cannot be listened for events.That's why I was trying to perform manual audit trails when attaching and detaching users to roles for example. For that I need the ids of the mentioned tables. These tables do not have assigned models and in case you want to retrieve this information you should make a query using the "DB" facade (this is how these records are registered, for example in
Conductors\AssignsRolesin$this->newPivotTableQuery()->insert().Another alternative to using the DB is to use the relationships of the
RoleandAbilitymodels, but in thesemorphToManyinformation about the id of the pivot table does not come.We can see this quickly with tinker:
The change adds the
idcolumns in the pivot relationships of theRoleandAbilitymodels as well as the traits to apply to theUsermodel.