Morcos Gad
Posted on February 17, 2022
I found this tip and wanted to share it with you so that you can benefit from it in your next projects, which is if you are not sure that this row exists in the database and want to avoid sending an error message when this row exists here, use insertOrIgnore
Laravel InsertOrIgnore With Eloquent
DB::table('users')->insertOrIgnore($data);
Laravel InsertOrIgnore Query With Eloquent Model
User::insertOrIgnore($data);
I hope you benefited and enjoyed this code with him. If you want to dig deeper, visit these sources
https://www.mysqltutorial.org/mysql-insert-ignore/
https://www.tutsmake.com/laravel-eloquent-insertorignore-example/
https://www.youtube.com/watch?v=hqiUzO8EFbM
💖 💪 🙅 🚩
Morcos Gad
Posted on February 17, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.