PHP code example of blood72 / laravel-jandi

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

    

blood72 / laravel-jandi example snippets


'providers' => [
    // ...
    Blood72\Jandi\JandiServiceProvider::class,
],

'aliases' => [
    // ...
    'Jandi' => \Blood72\Jandi\JandiFacade::class,
],

    use Blood72\Jandi\Notifications\Channels\JandiWebhookChannel;
    use GuzzleHttp\Client as HttpClient;
    use Illuminate\Notifications\ChannelManager;
    use Illuminate\Support\Facades\Notification;

    // ...

    Notification::resolved(function (ChannelManager $service) {
        $service->extend('jandi', function ($app) {
            return new JandiWebhookChannel(new HttpClient);
        });
    });
    

'jandi_webhook_url' => [
    env('JANDI_WEBHOOK_URL_1'),
    env('JANDI_WEBHOOK_URL_2'),
    // ... and so all
],

        $message = (new JandiMessage)->to('[email protected]');
        

        $message = (new JandiMessage)->content('hello test');
        

        $message = new JandiMessage('hello test');
        $message = JandiMessage::create('hello test');
        

        $message->color('#000000');
        $message->color('#30fe2a');
        

        $message->primary();
        $message->secondary();
        $message->success();
        $message->danger();
        $message->warning();
        $message->info();
        $message->light();
        $message->dark();
        

        $message->attachment(function ($attachment) {
            $attachment->title('attachment-title');
            $attachment->description('attachment-description');
            $attachment->image('attachment-image-url');
        });
        
        $message->attachment(function ($attachment) {
            $attachment->title('attachment-title');
            $attachment->description('attachment-description');
            $attachment->image('attachment-image-url');
        })->attachment(function ($attachment) {
            $attachment->title('attachment-another-title');
            $attachment->description('attachment-another-description');
            $attachment->image('attachment-another-image-url');
        });
        

        use Blood72\Jandi\Notifications\JandiNotification;
        
        class JandiExampleNotification extends JandiNotification
        {
            public function toJandi($notifiable/* = null*/): JandiMessage
            {
                return (new JandiMessage)->to('[email protected]')->content('hello test');
            }
        }
        

            use Illuminate\Notifications\AnonymousNotifiable;
            use Illuminate\Support\Facades\Notification;

            Notification::send(new AnonymousNotifiable, new JandiExampleNotification
            

            use Illuminate\Database\Eloquent\Model;
            use Illuminate\Notifications\Notifiable;
            
            class ExampleNotifiableModel extends Model
            {
                use Notifiable;

                public function routeNotificationForJandi()
                {
                    return 'hello routeNotificationForJandi() test';
                }
            }
            

            $notifiable = new ExampleNotifiableModel;
            
            $notification->send($notifiable, new JandiExampleNotification);
            

            use Blood72\Jandi\Notifications\Messages\JandiMessage;

            $message = JandiMessage::create('hello test');
            // or $message = new JandiMessage('hello test');
            
            Jandi::send($message);
            

            Jandi::send('hello test');
            

            Jandi::send('hello test', YourOtherNotification::class);
            

            Jandi::to('jandi-webhook-url')->send('hello test');
             

            Jandi::to('jandi-webhook-url-1', 'jandi-webhook-url-2')->send('hello test');
            

            Jandi::to([
                'jandi-webhook-url-1',
                'email-1' => 'jandi-webhook-url-2',
                'email-2' => [
                    'jandi-webhook-url-3',
                    'jandi-webhook-url-4',
                ],
            ]);
            
           
            use App\User;
            
            public function routeNotificationForJandi()
            {
                return 'url';
            }

            // in example, $user is User model instance.
            
            Jandi::to($user)->send('hello test');
            
bash
php artisan vendor:publish --provider="Blood72\Jandi\JandiServiceProvider"