add column id of pivot record in relations #619
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_roles
andpermissions
pivot 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\AssignsRoles
in$this->newPivotTableQuery()->insert()
.Another alternative to using the DB is to use the relationships of the
Role
andAbility
models, but in thesemorphToMany
information about the id of the pivot table does not come.We can see this quickly with tinker:
The change adds the
id
columns in the pivot relationships of theRole
andAbility
models as well as the traits to apply to theUser
model.