I have a Many-to-Many-Relationship between the User and the Customview Model:
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* Customview relation
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function customviews ()
{
return $this->belongsToMany( Customview::class )->withPivot( 'default' );
}
}
Now, I want to update all the user's customview-assignments and reset their default flag to 0.
By hand this should look like this in SQL (the pivot table's name is customview_user):
UPDATE `customview_user` SET `default`=0 WHERE `user_id`=<user_id>;
Is there a way to do this like this:
$user->customviews()->...update(['default' => 0]);
$this->customviews()->newPivotStatement()->where( 'user_id', $this->id )->update( [ 'default' => 0 ] );
– Degression