Skip to content
Advertisement

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

I have the following query:

JavaScript

and as expected I get the following result:

JavaScript

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

JavaScript

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.

JavaScript

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

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