0
0
Laravelframework~10 mins

Queued notifications in Laravel - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Queued notifications
Trigger Notification Event
Create Notification Instance
Queue Notification Job
Worker Picks Job from Queue
Send Notification (Email, SMS, etc.)
Mark Job as Completed
Done
This flow shows how Laravel queues a notification: event triggers, notification is queued, a worker sends it, then marks it done.
Execution Sample
Laravel
Notification::route('mail', 'user@example.com')
    ->notify(new InvoicePaid($invoice));
This code sends a notification to an email address using Laravel's notification system, which can be queued.
Execution Table
StepActionQueue StateWorker ActionNotification Status
1Trigger notificationEmptyIdleNot sent
2Create notification instanceEmptyIdleNot sent
3Queue notification jobJob added to queueIdleQueued
4Worker picks jobJob removed from queueProcessing jobSending
5Send notificationEmptySending email to user@example.comSent
6Mark job completedEmptyIdleCompleted
💡 Notification job processed and marked completed, queue is empty
Variable Tracker
VariableStartAfter Step 3After Step 4After Step 6
QueueEmpty1 jobEmptyEmpty
WorkerIdleIdleProcessing jobIdle
Notification StatusNot sentQueuedSendingCompleted
Key Moments - 3 Insights
Why does the notification not send immediately after calling notify()?
Because the notification is queued as a job (see Step 3 in execution_table), it waits in the queue until a worker processes it.
What happens if no worker is running?
The job stays in the queue (Step 3), and the notification remains unsent until a worker picks it up (Step 4).
How does Laravel know which channel to use for sending?
The notification class defines channels (mail, SMS, etc.), and the worker uses this info during sending (Step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the Queue State after Step 3?
AEmpty
BJob added to queue
CJob removed from queue
DProcessing job
💡 Hint
Check the 'Queue State' column at Step 3 in the execution_table.
At which step does the worker start processing the notification job?
AStep 2
BStep 3
CStep 4
DStep 5
💡 Hint
Look at the 'Worker Action' column to see when it changes from Idle to Processing job.
If the worker never runs, what happens to the Notification Status?
AIt stays Queued
BIt becomes Sending
CIt becomes Completed
DIt becomes Not sent
💡 Hint
Refer to the 'Notification Status' in variable_tracker after Step 3 and Step 4.
Concept Snapshot
Laravel queued notifications:
- Trigger notification event
- Notification instance created
- Job queued (not sent immediately)
- Worker processes job
- Notification sent via defined channel
- Job marked completed
Use queues to avoid delays in user requests.
Full Transcript
In Laravel, queued notifications work by first triggering a notification event. This creates a notification instance, which is then queued as a job instead of sending immediately. The queue holds the job until a worker process picks it up. The worker then sends the notification through the specified channel, such as email. After sending, the job is marked as completed and removed from the queue. This process helps keep user requests fast by handling notifications asynchronously.