Laravel - multi-insert rows and retrieve ids

前端 未结 2 1943
庸人自扰
庸人自扰 2021-01-02 10:00

I\'m using Laravel 4, and I need to insert some rows into a MySQL table, and I need to get their inserted IDs back.

For a single row, I can use ->insertGetI

2条回答
  •  醉话见心
    2021-01-02 10:30

    It's mysql behavior of last-insert-id

    Important
    If you insert multiple rows using a single INSERT statement, LAST_INSERT_ID() returns the value generated for the first inserted row only. The reason for this is to make it possible to reproduce easily the same INSERT statement against some other server.

    u can try use many insert and take it ids or after save, try use $data->id should be the last id inserted.

提交回复
热议问题