PHP code example of janyksteenbeek / laravel-bird-notifications

1. Go to this page and download the library: Download janyksteenbeek/laravel-bird-notifications 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/ */

    

janyksteenbeek / laravel-bird-notifications example snippets


'bird' => [
    'access_key' => env('BIRD_ACCESS_KEY'),
    'workspace' => env('BIRD_WORKSPACE_ID'),
    'channel' => env('BIRD_CHANNEL_ID'),
],

use NotificationChannels\Bird\BirdMessage;
use NotificationChannels\Bird\BirdChannel;

class OrderConfirmation extends Notification
{
    public function via($notifiable)
    {
        return [BirdChannel::class];
    }

    public function toBird($notifiable)
    {
        return (new BirdMessage())
            ->setBody("Your order #{$this->order->id} has been confirmed!")
            ->setRecipients($notifiable->phone_number);
    }
}

use NotificationChannels\Bird\BirdRoute;

class User extends Authenticatable
{
    public function routeNotificationForBird($notification)
    {
        return BirdRoute::make(
            recipients: [$this->phone_number],
            token: 'custom-access-token',        // optional
            workspace: 'custom-workspace-id',     // optional
            channel: 'custom-channel-id'         // optional
        );
    }
}

use NotificationChannels\Bird\BirdMessage;
use NotificationChannels\Bird\BirdRoute;

class OrderConfirmation extends Notification
{
    public function toBird($notifiable)
    {
        // Create a BirdRoute instance
        $route = BirdRoute::make(
            recipients: ['+31612345678', '+31687654321'],
            workspace: 'special-workspace-id',
            channel: 'urgent-channel-id'
        );

        // Create your message
        $message = (new BirdMessage())
            ->setBody("Your order #{$this->order->id} has been confirmed!");

        // Apply the route configuration
        if ($route->token) {
            $message->setAccessToken($route->token);
        }
        $message->setRecipients($route->recipients);

        return $message;
    }
}

public function toBird($notifiable)
{
    return (new BirdMessage())
        ->setBody('Your order has been confirmed!')
        ->setRecipients([
            '+31612345678',
            '+31687654321'
        ]);
}
bash
php artisan make:notification OrderConfirmation