Articles Snippets Projects

Save Eloquent Collection at once using the push() method

April 14th ʼ21 4 years ago

$user = User::find(1);
$user->name = 'new name';
$user->team->name = $user->name.'\'s team';

// Instead of saving all relationships separately
 $user->save();
 $user->team->save();

// You can save all relationships in single line
 $user->push();