Created
September 7, 2019 16:08
-
-
Save osbre/aee72ff8ce64d3daaec0f35c7dd445f6 to your computer and use it in GitHub Desktop.
Laravel notifications - how to use custom type
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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() | |
{ | |
// | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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