Skip to content

Conversation

@aydinfatih
Copy link
Contributor

The Problem:

When a ShouldQueue notification is dispatched:

  • By default, without viaQueues() or viaConnections() methods, all channels correctly utilize the notification's own $connection and $queue properties (e.g., 'redis' and 'admin_notifications') as their queue/connection settings.
  • However, if we define viaQueues() or viaConnections() to customize settings for only some channels, the channels that are not customized incorrectly bypass the notification's own default properties and fall back directly to the application's global default queue/connection settings.

Example Scenario:

  • App Defaults: QUEUE_CONNECTION=sync, Default Queue: base_queue
  • Notification Class Settings: $connection = 'redis', $queue = 'admin_notifications'
class AdminNotification extends Notification implements ShouldQueue
{
   use Queueable;

   public function __construct()
   {
       $this->connection = 'redis';
       $this->queue = 'admin_notifications';
   }
   
   public function via($notifiable)
   {
       return ['mail', 'database'];
   }
   
   public function viaQueues(): array
   {
       return ['mail' => 'mail_urgent'];
   }
   
   public function viaConnections()
   {
       return ['mail' => 'sqs'];
   }
  • Incorrect Behavior (Before Fix):
    • mail channel: Uses sqs connection, mail_urgent queue. (Correct)
    • database channel: Uses the database connection (Global Default) and the base_queue queue (Global Default). (INCORRECT) It should have used the notification's defaults (redis / admin_notifications).

The Fix:

This PR modifies the queue resolution logic. For channels not explicitly defined in viaQueues() or viaConnections(), Laravel will now first check and use the notification's own $queue or $connection properties. It will only fallback to the application's global defaults if the notification's properties are also unset.

  • Correct Behavior (After Fix):
    • mail channel: Uses redis connection, mail_urgent queue. (Correct)
    • database channel: Uses the redis connection (Notification Default) and the admin_notifications queue (Notification Default). (CORRECT)

@taylorotwell taylorotwell merged commit 0fc5528 into laravel:12.x Nov 2, 2025
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants