E
E
Eugene2020-02-23 10:06:31
Laravel
Eugene, 2020-02-23 10:06:31

How to bulk create records in db without foreach?

Hello.
Tell me how to rewrite this piece of code so that it would be $client->details()->create()filled without a cycle like here?

foreach ($request->client_details as $detail) {
                    $client->details()->create(
                        [
                            'client_id' => $client->id,
                            'name'      => $detail[ProductDetailsEnum::DETAIL_NAME],
                            'value'     => $detail[ProductDetailsEnum::DETAIL_VALUE],
                        ]
                    );
                }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2020-02-23
@Eugene70

https://laravel.com/docs/6.x/eloquent-relationship... - documentation is written to be read. I updated my knowledge and deleted the first answer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question