Back

Events on Pivot table


Hi there,

I've got two tables linked by a Many-to-Many relationship.

users

  • id

users_items

  • user_id
  • item_id

items

  • id

When querying for all the items a user has I'm caching the result. So now I'm trying to forget the Cache every time an item is attached / detached to the user.

I've found this little piece of code but unfortunately the event isn't fired (after placing it in the boot method of the User model):

Pivot::created(function ($pivot)) {
}

Any pointers as to how I can listen to attach / detach / sync?

Thanks in advance!

fico7489 replied 2 weeks ago

use this package https://github.com/fico7489/laravel-pivot


Sign in to participate in this thread!



We'd like to thank these amazing companies for supporting us