Answers for "save multiple models at once"

0

save multiple models at once

You can save multiple models at once using the saveMany function:

$post = Post::find(1);
$post->comments()->saveMany([
    new Comment(['message' => 'This a new comment']),
    new Comment(['message' => 'Me too!']),
    new Comment(['message' => 'Eloquent is awesome!'])
]);
Posted by: Guest on July-14-2021

Code answers related to "save multiple models at once"

Browse Popular Code Answers by Language