PHP code example of vrajroham / laravel-flock-notification

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

    

vrajroham / laravel-flock-notification example snippets


return FlockMessage::create()
    ->content('Laravel Flock Notification Channel')
    ->attachment(function ($attachment) {
                $attachment->title('Button Widget')
                    ->description('Description')
                    ->color('#fff000');
            });

public function routeNotificationForFlock()
{
    return $this->flock_webhook_url;
}



use Vrajroham\LaravelFlockNotification\FlockChannel;
use Vrajroham\LaravelFlockNotification\FlockMessage;
use Illuminate\Notifications\Notification;

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

    public function toFlock($notifiable)
    {
        return FlockMessage::create()
            ->content('Order created')
            ->attachments(function ($attachment) {
                $attachment->title('View order')
                    ->description('Order description')
                    ->color('#fff000');
            });
    }
}

        // Only 'src' field is mandatory.
        [
            [
                'src' => 'https://vrajroham.me/dl/vrajroham_cv.pdf', 
                'mime' => 'application/pdf', 
                'filename' => 'CV.pdf', 
                'size' => 2000 //bytes
            ],
            ...        
        ]
        

        [
            [
                'name' => 'Button Name',
                'icon' => 'https://avatars1.githubusercontent.com/u/12662173?s=460&v=4',
                'action' => [
                        'type' => 'openBrowser',
                        'url' => 'https://laravel.com',
                        'desktopType' => 'sidebar',
                    ],
                'id' => 'btn1'
            ],
            ...
        ]
        

public function toFlock($notifiable)
{
    return FlockMessage::create()
        ->content('This is text notification.');
}

public function toFlock($notifiable)
{
    return FlockMessage::create()
        ->content('This is text notification.')
        ->sendAs("Vaibhavraj", 'https://avatars1.githubusercontent.com/u/12662173?s=460&v=4');
}

public function toFlock($notifiable)
{
    return FlockMessage::create()
        ->attachments(function ($attachment){
                $attachment->title('This is error message.')
                ->color('#FF0000'); //Red
            });
}

public function toFlock($notifiable)
{
    return FlockMessage::create()
        ->notification('You have important message')
        ->content('This is text notification.');
}

public function toFlock($notifiable)
{
    return FlockMessage::create()
        ->attachments(function ($attachment){
                $attachment->title('Website as widget')
                ->views(function ($view){
                        $view->widget('https://vrajroham.me', 400, 400);
                    });
            });
}

public function toFlock($notifiable)
{
    return FlockMessage::create()
        ->attachments(function ($attachment){
                $attachment->title('This are the buttons')
                ->buttons([
                    [
                        'name' => 'Button 1',
                        'icon' => 'https://avatars1.githubusercontent.com/u/12662173?s=460&v=4',
                        'action' => [
                                'type' => 'openBrowser',
                                'url' => 'https://github.com/vrajroham',
                            ],
                        'id' => 'btn1'
                    ],
                    [
                        'name' => 'Button 2',
                        'icon' => 'https://laravel.com/favicon.png',
                        'action' => [
                                'type' => 'openBrowser',
                                'url' => 'https://laravel.com',
                            ],
                        'id' => 'btn2'
                    ]
                ]);
        });
}

public function toFlock($notifiable)
{
    return FlockMessage::create()
        ->attachments(function ($attachment) {
             $attachment->title('Image as attachment')
             ->views(function ($view) {
                 $view->image(function ($image)
                 {
                     $image->original('https://avatars1.githubusercontent.com/u/12662173?s=460&v=4',400,400)
                     ->thumbnail('https://avatars1.githubusercontent.com/u/12662173?s=460&v=4',100,100)
                     ->filename('vaibhavraj.png');
                 });
             });
         });
}

public function toFlock($notifiable)
{
    return FlockMessage::create()
        ->attachments(function ($attachment) {
             $attachment->title('Download link')
             ->downloads([
                [
                    'src' => 'https://vrajroham.me/dl/vrajroham_cv.pdf',
                    'mime' => 'application/pdf',
                    'filename' => 'file-1.pdf',
                    'size' => 1500
                ],
             ]);
         });
}