Skip to content
Advertisement

How to update data of pivot table in Many To Many relationship

I have a Many To Many relationshp between User Model & Wallet Model.

So at the User.php Model:

JavaScript

And at Wallet.php Model:

JavaScript

And also the table Migration of user_wallet table also goes here:

JavaScript

And at the Controller, I added this:

JavaScript

But now I need to update balance filed of this pivot table which has the same user_id and wallet_id:

enter image description here

So how to do this?

I would really appreciate any idea or suggestion from you guys…

Thanks in advance.

Advertisement

Answer

use updateExistingPivot

JavaScript

Ref:https://laravel.com/docs/8.x/eloquent-relationships#updating-a-record-on-the-intermediate-table

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement