This package gives you ability to change notification type (instant or via queue) dynamically.
Via Composer
$ composer require spinyman/laravel-will-queue
-
First of all you have to deimplement ShouldQueue interface from all notification models:
class EmailNotification extends Notification
implements ShouldQueue -
Make changes in User model:
use Illuminate\Notifications\Notifiable;use SpinyMan\WillQueue\Notifiable;
use SpinyMan\WillQueue\Notifiable; class User extends Authenticatable { use Notifiable; ... }
-
somewhere use notify function with second optional bool param to indicate queue (true) or instant (false) notification (default: false):
$user = User::find(1); $user->notify(new EmailNotification() [, true|false]);
OR if you are really sure to notify using queue:
$user = User::find(1); $user->notifyFromQueue(new EmailNotification());