PHP code example of pschocke / laravel-notification-settings

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

    

pschocke / laravel-notification-settings example snippets


$model->saveNotificationSettingFromRequest($request);

$model->sendNotification(new OrderReceivedNotification($order); // this model will receive the notification on all channels he has configured



return [
    /**
     * The Settings the user can choose if he wants to be notified at a given event
     */
    'settings' => [

        /**
         * The default model. Add more if you want different settings for different models
         */
        'default' => [

            /**
             * The default events for this model. Add a new array with the notitication key to have different settings for different notification channels
             */
            'default' => [
                'event1' => 'description1',
                'event2' => 'description2',
            ],
        ],
    ],

    'verificationNotification' => pschocke\NotificationSettings\Notifications\NotificationSettingVerificationNotification::class,

    'handler' => [
        'mail' => pschocke\NotificationSettings\Handler\MailHandler::class,
    ],

    'driver' => [
        'mail' => [
            'verification' => [
                'enabled' => true,
                'method' => 'link',
            ],
        ],
    ],
];

    'settings' => [
        App\Team::class => [
            'default' => [
                'mySetting' => 'description',
            ]
        ]
        'default' => [
            'default' => [
                'setting1' => 'description1',
                'setting2' => 'description2',
            ],
        ],
    ],


    'settings' => [
        App\Team::class => [
            'default' => [
                'mySetting' => 'description',
            ]
            'mail' => [
                'mailSetting' => 'mailDescription',
            ]
        ]
        'default' => [
            'default' => [
                'setting1' => 'description1',
                'setting2' => 'description2',
            ],
        ],
    ],


$myModel->saveNotificationSetting([
  'type' => 'mail',                 // the key of the handler
  'meta' => [                       // everything configured in the handler as ;

$myModel->sendNotification(new OrderShippedNotification($notification), 'orderShipped'); // the second parameter is the setting name.

namspace App\NotificationSettingHandler;

use pschocke\NotificationSettings\Models\NotificationSetting;
use pschocke\NotificationSettings\Handler\Handler;
use pschocke\NotificationSettings\Handler\HandlerInterface;

class SlackHandler extends Handler implements HandlerInterface
{

    protected $request = [
        'webhook' => ['       return $methodName === 'routeNotificationForSlack';  // the method name to route the notification
    }

    public function getSend(NotificationSetting $notificationSetting) // returns what is needed to route the notification
    {
        return $notificationSetting->meta['webhook'];
    }
}

'handler' => [
    'mail' => pschocke\NotificationSettings\Handler\MailHandler::class,
    'slack' => App\NotificationSettingHandler\SlackHandler::class,
],
bash
php artisan vendor:publish --provider="pschocke\NotificationSettings\NotificationSettingsServiceProvider" --tag="migrations"
php artisan migrate
bash
php artisan vendor:publish --provider="pschocke\NotificationSettings\NotificationSettingsServiceProvider" --tag="config"