tomspeak
5 months ago

Using increment() to update an extra column on a Many-Many pivot table?

Posted 5 months ago by tomspeak

Hi,

I am trying to take an authenticated user in a request, and update the many-to-many pivot table between a User and Project. I can do this with static data, but now I want to use increment() to do this atomically.

An example of my static code:

request()
            ->user()
            ->projects()
            ->updateExistingPivot($project->id, [
                'spent' => '123456789',
                'paid' => '987654321'
            ]);

How would I go about incorporating increment() into this query? I am still new and am not sure when to reach for the query builder, vs uncovering an Eloquent method.

Cheers

Please sign in or create an account to participate in this conversation.