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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners