0

I was playing with laravel Eloquent and found that it doesn't support Batch Insert i.e.multiple row at once like

Model::insert($array_of_data);

What is the reason for this ?

Thank you for any suggestion .

Drudge Rajen
  • 7,584
  • 4
  • 23
  • 43
  • [Duplicate](http://stackoverflow.com/questions/12702812/bulk-insertion-in-laravel-using-eloquent-orm)? If not, what do you expect to see as a suitable answer? – raina77ow Sep 13 '16 at 17:44
  • I think you can ---> http://stackoverflow.com/questions/31356345/insert-batch-in-laravel-5 – The One and Only ChemistryBlob Sep 13 '16 at 17:44
  • @raina77ow yeah i have seen this answer, but using query builder it doesn't update timestamps right?? – Drudge Rajen Sep 13 '16 at 17:46
  • But there was [an answer](http://stackoverflow.com/a/26569967/1229023) in that thread dealing with timestamps, no? – raina77ow Sep 13 '16 at 17:47
  • Yes, And Yes we can do this batch insert in many ways in our own but my question is why it is not in eloquent yet ?? – Drudge Rajen Sep 13 '16 at 17:48
  • 1
    We're not the ones to ask why. You'll want to go directly to the coders for that. We just work with what they've built. – aynber Sep 13 '16 at 17:51
  • and i think knowing these thing is not illegal :) , right ? – Drudge Rajen Sep 13 '16 at 17:52
  • 1
    Are you sure using SO for this particular question is better than using Laravel issue tracker - [which actually already has one](https://github.com/laravel/framework/issues/1295)? – raina77ow Sep 13 '16 at 17:59
  • I thought i will get some idea about this issue here so i posted it in SO. But now i think i should close the question . :) – Drudge Rajen Sep 13 '16 at 18:08

1 Answers1

0

It doesn't because of for models you might have extended logic. For example when creating new database entry you might want to to verify previous records to find out for example this record identifier and doing it with single query is not possible, so you can either you use batch inserts using query builder or simple use loop to create many records but in case of multiple records in 2nd case it might obviously affect performance.

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291