laravel / ideas

Issues board used for Laravel internals discussions.
938 stars 28 forks source link

[Request] CreateMany in eloquent #1334

Open hirenkeraliya opened 5 years ago

hirenkeraliya commented 5 years ago

Can you Makee functionality of the createMany in eloquent if no then why?

mfn commented 5 years ago

What are you missing from <Model>::insert? It's a forward to \Illuminate\Database\Query\Builder::insert, e.g.:

Post::insert([
  [
    'title' => 'Title 1',
  ],
  [
    'title' => 'Title 2',
  ]
);

It has certain restrictions (requires the same keys everywhere, doens't use mutators) but otherwise is very efficient.

hirenkeraliya commented 5 years ago

If my input is <input type="text" class="form-control" name="comments[]"> when i try to insert not works because the same key is not exists.

chuck-wood commented 5 years ago

insert doesn't fill in timestamps, and it doesn't seem to pay attention to the $fillable array.