Skip to content

Instantly share code, notes, and snippets.

@osbre
Created September 7, 2019 16:08
Show Gist options
  • Save osbre/aee72ff8ce64d3daaec0f35c7dd445f6 to your computer and use it in GitHub Desktop.
Save osbre/aee72ff8ce64d3daaec0f35c7dd445f6 to your computer and use it in GitHub Desktop.
Laravel notifications - how to use custom type
<?php
namespace App\Providers;
use App\Notifications\DatabaseChannel as CustomDatabaseChannel;
use Illuminate\Notifications\Channels\DatabaseChannel;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(
DatabaseChannel::class,
CustomDatabaseChannel::class
);
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
}
<?php
namespace App\Notifications;
use Illuminate\Notifications\Channels\DatabaseChannel as Channel;
use Illuminate\Notifications\Notification;
class DatabaseChannel extends Channel
{
protected function buildPayload($notifiable, Notification $notification)
{
return ['type' => $notification->type ?? get_class($notification)]
+ parent::buildPayload($notifiable, $notification);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment