Laravel 5 update all Pivot entries Laravel 5 update all Pivot entries laravel laravel

Laravel 5 update all Pivot entries


You may have moved on from this, but for posterity I'll reply anyway as I found this question via Google.

It's hacky, but this does the trick:

$user->customviews()    ->newPivotStatement()    ->where('user_id', '=', $user->id)    ->update(array('default' => 0));


Try with updateExistingPivot like this:

$user->customviews()->updateExistingPivot($customviewId, ['default' => 0]);