I am storing multiple posts in a model like:
foreach($users as $user)
{
$post = new Post;
$post->user_id = $user->id;
$post->save();
}
Now if I have 20 users
I will have 20 new Posts
,
Question:
How do I get the 20 posts back after save()
?
You should try this:
You can get an array of inserted posts like this:
You also can convert it to a collection after the
foreach
loop: