Created
March 9, 2025 16:36
-
-
Save herisulistiyanto/81b63e308fb5956ccf0ed381ee85c8d8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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\Bus\Queueable; | |
use App\Channels\FirebaseChannel; | |
use Illuminate\Notifications\Notification; | |
use Illuminate\Contracts\Queue\ShouldQueue; | |
class GenericFirebaseNotification extends Notification implements ShouldQueue | |
{ | |
use Queueable; | |
protected $token; | |
protected $title; | |
protected $body; | |
protected $data; | |
/** | |
* Create a new notification instance. | |
* | |
* @param string $token Device token of the target device. | |
* @param string $title Notification title. | |
* @param string $body Notification body. | |
* @param array $data Optional extra data payload. | |
*/ | |
public function __construct(string $token, string $title, string $body, array $data = []) | |
{ | |
$this->token = $token; | |
$this->title = $title; | |
$this->body = $body; | |
$this->data = $data; | |
} | |
/** | |
* Get the notification's delivery channels. | |
* | |
* @param mixed $notifiable | |
* @return array | |
*/ | |
public function via($notifiable) | |
{ | |
return [FirebaseChannel::class]; | |
} | |
/** | |
* Get the array representation of the notification. | |
* | |
* @param mixed $notifiable | |
* @return array | |
*/ | |
public function toFirebase($notifiable) | |
{ | |
return [ | |
'token' => $this->token, | |
'title' => $this->title, | |
'body' => $this->body, | |
'data' => $this->data, | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment