Skip to content

How to insert multiple items in embeds many? #2429

Answered by JenuelDev
JenuelDev asked this question in Q&A
Discussion options

You must be logged in to vote

It seems I figured it out. It would be awesome if we could add this inside the documentation that way, when people is looking for it it will be easy.

I was able to figure it out by using a function createMany.

example:

$post = Post::create([
                'title' => $this->title,
                'content' => $this->content
            ]);

$tags = array_map(function ($tag) {
                return ['name' => $tag];
            }, $this->tags);

$post->tags()->createMany($tags);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by JenuelDev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant