Category: Laravel

When you want to rollback a set of database operations if one of them fails, you can execute them within a database transaction. Imagine, you have a database with 10.000 users and want to inactivate all users that don't have a subscription. When the update query is executing, something may fail, and you can end up with inconsistent results in you users table.

When you only are adding a single statement to a transaction, Laravel provides three shorthand methods, saveOrFail, updateOrFail, and deleteOrFail.

Let's look at the definition of saveOrFail: The save method, is added to a transaction when executed by saveOrFail.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners