Answers for "laravel many to many update all pivot"

PHP
2

laravel many to many relationship with pivot table

$user = User::find(1); //any user we want to find 
$user->trophies()->attach($idOfTrophy); 
//pass id or array of a Trophy ids 
//suppose admin has selected the trophy from a form and trophy id
// is in $request object, then.
$trophyId = $request->trophy_id;
$user->trophies()->attach($trophyId); //record is created in DB.
attach and syncWithoutDetaching both does same job
Posted by: Guest on January-20-2021
0

laravel many to many update all pivot

$user->customviews()
    ->newPivotStatement()
    ->where('user_id', '=', $user->id)
    ->update(array('default' => 0));
Posted by: Guest on April-30-2020

Code answers related to "laravel many to many update all pivot"

Browse Popular Code Answers by Language