1. Go to this page and download the library: Download uzinfo/ntfy-laravel 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/ */
uzinfo / ntfy-laravel example snippets
namespace App\Events;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class NotificationEvent implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public function __construct(
public string $message,
public int $userId,
public ?string $title = null
) {}
public function broadcastOn()
{
return new Channel('user.' . $this->userId);
}
public function broadcastWith()
{
return [
'message' => $this->message,
'title' => $this->title,
'priority' => 4,
'tags' => ['notification', 'alert'],
];
}
}
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use UzInfo\NtfyLaravel\NtfyChannel;
use UzInfo\NtfyLaravel\NtfyMessage;
class OrderShipped extends Notification
{
public function via($notifiable)
{
return [NtfyChannel::class];
}
public function toNtfy($notifiable)
{
return NtfyMessage::create('Your order has been shipped!')
->title('Order Update')
->priority(4)
->tags(['package', 'shipped'])
->click('https://example.com/track/123')
->icon('📦');
}
}
class User extends Model
{
public function routeNotificationForNtfy()
{
return 'user-' . $this->id;
}
}