1. Go to this page and download the library: Download glueful/notiva library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Glueful\Notifications\Contracts\Notifiable;
class User implements Notifiable
{
public function getNotifiableId(): string { return $this->uuid; }
public function shouldReceiveNotification(string $type, string $channel): bool { return true; }
public function getNotificationPreferences(): array { return []; }
public function routeNotificationFor(string $channel)
{
if ($channel !== 'push') return null;
return [
'fcm' => ['fcm-token-1'],
'apns' => ['apns-token-1'],
// 'webpush' => [[ 'endpoint' => '...', 'keys' => ['p256dh' => '...', 'auth' => '...'] ]]
];
}
}
use Glueful\\Notifications\\Services\\NotificationDispatcher;
use Glueful\\Notifications\\Models\\Notification;
use App\\Models\\User; // your Notifiable implementation
$dispatcher = container()->get(NotificationDispatcher::class);
// Build a Notification model; type is arbitrary for your domain
$notification = new Notification([
'type' => 'system_alert',
'data' => [
'title' => 'Hello',
'body' => 'World',
'data' => ['foo' => 'bar'],
// optional per-channel fields supported as in the direct example
],
]);
$user = User::findByUuid('u_ABC123');
// Restrict to the push channel explicitly
$result = $dispatcher->send($notification, $user, ['push']);