Skip to content
Advertisement

Do not stop loop when query fails. LARAVEL

I am uploading a .csv file to a controller in my laravel application, and the controller loops through all the rows of the file and create new rows in my database. I works pretty well, but the problem is that if one of the rows of the CSV has a problem, the loop will be stopped and the web page will show the error with the query problem (that can be whatever was wrong in the CSV file). But what I want, is that whenever one row can’t be saved, the controller omits that row and keep working with the next ones. This is the function of my controller:

JavaScript

I have also tried with the try catch but I’m not quite sure of how to use it correctly.

JavaScript

Thanks a lot, I will totally appreciate any help.

Advertisement

Answer

Not sure if thats what you did but try this

JavaScript

Also, if its something wrong with the file, it would not be QueryException

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement