44 lines
1.0 KiB
PHP
44 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Notifications\Notification;
|
|
use NotificationChannels\WebPush\WebPushChannel;
|
|
use NotificationChannels\WebPush\WebPushMessage;
|
|
|
|
class NewActivityNotification extends Notification
|
|
{
|
|
use Queueable;
|
|
|
|
public array $activity;
|
|
|
|
public function __construct(array $activity)
|
|
{
|
|
$this->activity = $activity;
|
|
}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return [WebPushChannel::class, 'database'];
|
|
}
|
|
|
|
public function toWebPush(object $notifiable): WebPushMessage
|
|
{
|
|
return (new WebPushMessage)
|
|
->title('New Activity')
|
|
->icon('/apple-touch-icon.png')
|
|
->body($this->activity['content'])
|
|
->action('View', 'view')
|
|
->data(['url' => $this->activity['url']]);
|
|
}
|
|
|
|
public function toArray(object $notifiable): array
|
|
{
|
|
return [
|
|
'content' => $this->activity['content'],
|
|
'url' => $this->activity['url'],
|
|
];
|
|
}
|
|
}
|