How to mix disable notifications in Laravel 9 Code answer

In this article, we will learn about How to mix disable notifications in Laravel

In Laravel 9, you can disable notifications by creating a new Notifications service provider and overriding the shouldSendNotification method. Here’s an example of how you can do this:

  1. Create a new service provider by running the command php artisan make:provider DisableNotificationsServiceProvider
  2. In the register method of the service provider, override the ShouldSendNotification method by adding the following code:
use Illuminate\Notifications\ChannelManager;
use Illuminate\Support\ServiceProvider;

class DisableNotificationsServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->extend(ChannelManager::class, function ($manager) {
            $manager->extend('mail', function () {
                return new class {
                    public function send($notifiable, $notification)
                    {
                        // Do not send notifications
                    }
                };
            });
        });
    }
}

3). Add the service provider in the providers array in config/app.php

'providers' => [
    // ...
    App\Providers\DisableNotificationsServiceProvider::class,
],

This will now disable the notifications on the mail channel. You can customize this to disable other channels as well.

Discover more from STRUGGLER KING.COM

Subscribe now to keep reading and get access to the full archive.

Continue Reading