Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aurawindsurfing's avatar

How to build new custom notification driver

Hi!

Is there any good example tutorial how to build new notification driver please? We use sendinblue.com for our transactional emails it works very well and it is really well priced.

They provide own class mailin.php but I'm not sure how to add it to new laravel in order to be able to reuse it easily.

The code used for sending is here:

require('../mailin.php');
    $mailin = new Mailin("https://api.sendinblue.com/v2.0","your access key");
    $data = array( "id" => 2,
      "to" => "[email protected]|[email protected]",
      "cc" => "[email protected]'",
      "bcc" => "[email protected]",
      "replyto" => "[email protected]",
      "attr" => array("EXPEDITEUR"=>"His name","SUBJECT"=>"This is my subject"),
      "attachment_url" => "",
      "attachment" => array("myfilename.pdf" => "your_pdf_files_base64_encoded_chunk_data"),
      "headers" => array("Content-Type"=> "text/html;charset=iso-8859-1", "X-param1"=> "value1", "X-param2"=> "value2", "X-Mailin-custom"=>"my custom value","X-Mailin-tag"=>"my tag value")
    );

Source is here: https://apidocs.sendinblue.com/template/#1

This example sends a template with set of params just like a slack notification with and array of params.

Cheers!

0 likes
9 replies
aurawindsurfing's avatar

Cheers Vincent,

I also found those 2 bits of info. This way you can add custom notification class to your app and replace a default lets say e-mail reset notification:

Custom Channels

Laravel ships with a handful of notification channels, but you may want to write your own drivers to deliver notifications via other channels. Laravel makes it simple. To get started, define a class that contains a send method. The method should receive two arguments: a $notifiable and a $notification:


namespace App\Channels;

use Illuminate\Notifications\Notification;

class VoiceChannel
{
    /**
     * Send the given notification.
     *
     * @param  mixed  $notifiable
     * @param  \Illuminate\Notifications\Notification  $notification
     * @return void
     */
    public function send($notifiable, Notification $notification)
    {
        $message = $notification->toVoice($notifiable);

        // Send notification to the $notifiable instance...
    }
}

Once your notification channel class has been defined, you may simply return the class name from the via method of any of your notifications:


namespace App\Notifications;

use Illuminate\Bus\Queueable;
use App\Channels\VoiceChannel;
use App\Channels\Messages\VoiceMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;

class InvoicePaid extends Notification
{
    use Queueable;

    /**
     * Get the notification channels.
     *
     * @param  mixed  $notifiable
     * @return array|string
     */
    public function via($notifiable)
    {
        return [VoiceChannel::class];
    }

    /**
     * Get the voice representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return VoiceMessage
     */
    public function toVoice($notifiable)
    {
        // ...
    }
}

And then this one:

Reset Email Customization

You may easily modify the notification class used to send the password reset link to the user. To get started, override the sendPasswordResetNotification method on your User model. Within this method, you may send the notification using any notification class you choose. The password reset $token is the first argument received by the method:

/**
 * Send the password reset notification.
 *
 * @param  string  $token
 * @return void
 */
public function sendPasswordResetNotification($token)
{
    $this->notify(new ResetPasswordNotification($token));
}

Hope it will help someone!

1 like
aurawindsurfing's avatar

And yes building the driver would be the best thing to do of course. Will try to do this once I figure it all out.

aurawindsurfing's avatar

@willvincent I can not figure it out. I'm always getting

InvalidArgumentException in Manager.php line 90: Driver [WebhookChannel::class] not supported.

while trying to implement a new class into /Notifications

Any ideas what I'm doing wrong please?

willvincent's avatar

I've not used, let alone extended, the notifications.. haven't really touched laravel 5.3 more that just to look at the changes to the directory structure at this point... so, sorry no I don't have any insight for you.

yasht's avatar

I have created using this guide and documentation.

  1. Custom Driver Created
  2. Created Notification
  3. Called Notification

Getting this in response

InvalidArgumentException: Driver [App\Channels\TextLocalChannel] not supported. in

stanliwise's avatar

Are you sure that Driver channel path is correct and the name of the file including the namespace match correctly? More so do a composer dump autoload to be sure it is discovered by composer autoloader. Lastly your Channel must conform to the interface of having send() method which it accept notifiable and the notification arguments.

Please or to participate in this conversation.