update send notification fcm
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
namespace App\Models\OLDLMS;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -9,11 +9,14 @@ class NotificationToken extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $connection = 'oldlms';
|
||||
|
||||
protected $fillable = [
|
||||
'origin',
|
||||
'type',
|
||||
'token',
|
||||
'status',
|
||||
'device_id'
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\OLDLMS;
|
||||
|
||||
use App\Models\NotificationToken;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
@@ -16,7 +14,7 @@ use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable, Notifiable;
|
||||
use HasFactory, SoftDeletes, HasApiTokens, HasRoles, Notifiable;
|
||||
|
||||
const CREATED_AT = 'dCreateOn';
|
||||
const UPDATED_AT = 'dUpdateOn';
|
||||
@@ -40,6 +38,7 @@ class User extends Authenticatable
|
||||
'nIDHubunganKeluarga',
|
||||
'dUpdateOn',
|
||||
'sIPAddress',
|
||||
'fcm_token',
|
||||
];
|
||||
|
||||
protected function fullName(): Attribute
|
||||
@@ -73,4 +72,6 @@ class User extends Authenticatable
|
||||
{
|
||||
return $this->morphMany(NotificationToken::class, 'notifiabletoken');
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
39
app/Notifications/SendNotification.php
Normal file
39
app/Notifications/SendNotification.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use NotificationChannels\Fcm\FcmChannel;
|
||||
use NotificationChannels\Fcm\FcmMessage;
|
||||
|
||||
class SendNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
private $title;
|
||||
private $body;
|
||||
private $data;
|
||||
|
||||
public function __construct($title, $body, $data)
|
||||
{
|
||||
$this->title = $title;
|
||||
$this->body = $body;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function via($notifiable)
|
||||
{
|
||||
return [FcmChannel::class];
|
||||
}
|
||||
|
||||
public function toFcm($notifiable)
|
||||
{
|
||||
return FcmMessage::create()
|
||||
->setData($this->data) // Menggunakan $this->data
|
||||
->setNotification([
|
||||
'title' => $this->title,
|
||||
'body' => $this->body,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user