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

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