Skip to content
Advertisement

How to insert multiple rows from a single query using eloquent/fluent

I have the following query:

and as expected I get the following result:

Is there a way of copying the above result into another table so that my table looks like this?

The problem I have is that the $query can expect any number of rows and so im unsure how to iterate through an unknown number of rows.

Advertisement

Answer

It is really easy to do a bulk insert in Laravel using Eloquent or the query builder.

You can use the following approach.

In your case you already have the data within the $query variable.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement