hi, instead of chunk collection by 500 records and loop through each chunk, Would it be better if we insert directly 20000 models into database with the code below?
Employee::insert($employees->toArray());
This will produce only one query instead of 40 queries.
Yes but insert() doesn't take care of timestamps fields and any Eloquent listeners.
And 1 long query is not always faster than 40 shorter ones. You should actually test it out, I guess.
hi, instead of chunk collection by 500 records and loop through each chunk, Would it be better if we insert directly 20000 models into database with the code below?
This will produce only one query instead of 40 queries.
Thank you
Yes but
insert()
doesn't take care of timestamps fields and any Eloquent listeners. And 1 long query is not always faster than 40 shorter ones. You should actually test it out, I guess.