PHP code example of justpush / laravel-notification-channel

1. Go to this page and download the library: Download justpush/laravel-notification-channel 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/ */

    

justpush / laravel-notification-channel example snippets


'justpush' => [
    'token' => env('JUSTPUSH_TOKEN'),
    // 'timeout' => 10,  // seconds
],

use Illuminate\Notifications\Notification;
use NotificationChannels\JustPush\JustPushChannel;
use NotificationChannels\JustPush\JustPushMessage;

class OrderShipped extends Notification
{
    public function __construct(private Order $order) {}

    public function via($notifiable): array
    {
        return [JustPushChannel::class]; // or ['justpush']
    }

    public function toJustPush($notifiable): JustPushMessage
    {
        return JustPushMessage::create("Order #{$this->order->number} is on its way")
            ->title('📦 Order shipped')
            ->topic('Orders')
            ->button('Track', $this->order->trackingUrl);
    }
}

   public function routeNotificationForJustPush($notification): ?string
   {
       return $this->justpush_token;
   }
   

   Notification::route('justpush', $token)->notify(new ServerDown($server));
   

JustPushMessage::create('Water detected under the washing machine')
    ->title('💧 Leak')
    ->topic('Home')                       // topic name; created if it doesn't exist
    ->highestPriority()                   // or ->priority(2) / ->priority('highest')
    ->sound('siren')
    ->button('Open camera', 'https://example.com/cam', actionRequired: true)
    ->buttonGroup('Rooms', 'Cameras', [
        ['cta' => 'Kitchen', 'url' => 'https://example.com/cam/kitchen'],
        ['cta' => 'Hall', 'url' => 'https://example.com/cam/hall'],
    ])
    ->image('https://example.com/snapshot.jpg', 'Kitchen')   // or ->imageData($bytes) / ->imageFile($path)
    ->expiresIn(3600)
    ->acknowledge(retryEvery: 60, maxRetries: 10, callbackUrl: route('justpush.acknowledged'), callbackParams: ['leak' => 42]);

['status' => 1, 'key' => 'abc123…', 'rate_limit' => ['limit' => 10000, 'remaining' => 9895, 'reset_seconds' => 234512]]