Category: Laravel

Dec 16, 2020 — 2 min Read — #databases#queues#notifications You group multiple database queries into a single transaction, these queries will only take effect if they all succeed. Consider the following code: If the team creation fails, a user will be left in your system with no team. To prevent this from happening, you can wrap the block inside a transaction: Now if the team creation fails, the entire transaction will be rolled back, including the query that creates the user.

Any other code you may include inside the transaction will be executed right away and will not wait for after the transaction has committed: In the example above, the welcome email will be sent to the user even if the team creation fails and the user record was not stored in the database.
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