- Implemented push notifications with a service worker (sw.ts) to handle caching and notifications. - Added API routes for push subscription and notification management in routes/api.php. - Created NotificationTest to validate notification service functionality and ensure correct notifications are sent based on user roles and actions. - Updated Permissions component to manage notification permissions and subscriptions. - Enhanced CategoryIndex component to highlight categories based on notifications. - Excluded service worker from TypeScript compilation in tsconfig.json. - Updated Vite configuration to include service worker in the build process.
34 lines
838 B
PHP
34 lines
838 B
PHP
<?php
|
|
|
|
namespace App\Notifications;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Notifications\Notification;
|
|
use NotificationChannels\WebPush\WebPushChannel;
|
|
use NotificationChannels\WebPush\WebPushMessage;
|
|
|
|
class WebPushNotification extends Notification implements ShouldQueue
|
|
{
|
|
use Queueable;
|
|
|
|
public function __construct(
|
|
public string $title,
|
|
public string $body,
|
|
public string $icon = '/icon-192x192.png',
|
|
) {}
|
|
|
|
public function via(object $notifiable): array
|
|
{
|
|
return [WebPushChannel::class];
|
|
}
|
|
|
|
public function toWebPush(object $notifiable, mixed $notification): WebPushMessage
|
|
{
|
|
return (new WebPushMessage)
|
|
->title($this->title)
|
|
->icon($this->icon)
|
|
->body($this->body);
|
|
}
|
|
}
|