mercredi 27 novembre 2019

Updating Existing Record of Pivot Table in Laravel. How to use updateExistingPivot when I do not have second parameter?

The two tables sites and terms have many to many relationship. The pivot table for them is:

site_terms 
----------
site_id
term_id 

While saving a site and its relationship with the terms work fine with the following:

$site->terms()->attach($term_id);

Say I have added a site to a term and the record is in the table:

site_term 
-----------
site_id term_id 
101     501

When I edit the site and add a different term whose id is 502 how can I update the record of the relationship in the pivot table so that the record is now

site_term 
-----------
site_id term_id 
101     502


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2L2G1Pz
via IFTTT

Aucun commentaire:

Enregistrer un commentaire