save() because of code " /> save() because of code " /> save() because of code "/>

Laravel eloquent doesn't insert data when bug occur during multiple insert

345 Views Asked by At

I'm trying to insert users using csv. My model has an observer on "created" event.

However I can have a bug after some $users->save() because of code in my function created event (which I fixed).

The code in created event send an email to the user. The problem is if code crash after 5iterations, I got my 5emails send but no user in my db.

I'm wondering if Eloquent use transaction when you call multiple times save() ? If yes how to force Eloquent to really save my object after each end of event created ?

May be I'm misunderstanding something with event, because I don't see the point of using this event if your not sure to have your model insert in your DB.

1

There are 1 best solutions below

0
user1904731 On

Finally found what was wrong...

To insert csv my project use : https://github.com/Maatwebsite/Laravel-Excel

And after some research, this is "why" eloquent use transaction in my case : https://docs.laravel-excel.com/3.1/imports/validation.html#database-transactions