Laravel-Hub.com
thefeqy's profile
Muhammed Elfeqy@thefeqy•Nov 19, 2025
350
Post cover image

Laravel Tip: Dispatch Jobs After Your DB Transaction Commits

From laravel-hub.com•Nov 19, 2025•2m read time

Jobs dispatched inside database transactions can execute before the transaction commits, causing race conditions where the job queries non-existent data. Laravel's afterCommit() method ensures jobs only run after the transaction completes successfully. This can be applied per-dispatch using ->afterCommit() or globally on the job class with $afterCommit = true. Essential for scenarios like sending confirmation emails, syncing with external APIs, or indexing records where the job depends on committed database changes.

Sort:

thefeqy's user avatar
Muhammed Elfeqy
@thefeqy
Joined Mar 5. 2024
350

My name is Muhammed Elfeqy, an ambitious software engineer from Egypt with a passion for technology,

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard