PHP code example of sashagm / notification

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

    

sashagm / notification example snippets


NF_EMAIL= 
TELEGRAM_API_KEY = 
TELEGRAM_CHAT_ID = 
NF_URL=/custom/notifications
NF_ROUTE_NAME=custom-nf

    'telegramApiKey'    => env('TELEGRAM_API_KEY'),
    'chatId'            => env('TELEGRAM_CHAT_ID'),
    'email'             => env('NF_EMAIL'),
    'vkToken'           => env('VK_TOKEN'),
    'vkUserId'          => env('VK_USER_ID'),
    'logger'            => true, // Разрешить логирование

    'check'             => [

        'active'        => true, // True Разрешить проверку или false Пропускать проверку
        'guard'         => 'web', // Укажите через какой гард будет работать

        'save_colum'    => 'id', // Поле для группы/роли или прав
        'save_value'    => [
            1, 2, 3
        ], // добавляем массив значений

    ],
    
    'routes'            => [

        'url'           => env('NF_URL', '/notifications'),
        'routeName'     => env('NF_ROUTE_NAME', 'nf'),

    ],

{
    "type": "email", // для отправки на почту
    "message": "Hello, world!"
    //'id': '[email protected]' email, 12345678 чат ид
    // id не обязательный парамтр если он не передан то уведомление будет отправлены по дефолтным данным из .env
}

{
    "type": "telegram", // для отправки в телеграм
    "message": "Hello, world!"
    //'id': '[email protected]' email, 12345678 чат ид
    // id не обязательный парамтр если он не передан то уведомление будет отправлены по дефолтным данным из .env
}

{
    "type": "all", // для отправки в все каналы
    "message": "Hello, world!"
}

use Sashagm\Notification\Services\NotificationService;

$notificationService = new NotificationService();
$message = 'This is a test email notification.';
$notificationService->sendEmail($message);

use Sashagm\Notification\Services\NotificationService;

$notificationService = new NotificationService();
$message = 'This is a test Telegram notification.';
$notificationService->sendTelegram($message);

use Sashagm\Notification\Services\NotificationService;

$notificationService = new NotificationService();
$message = 'This is a test all chanel notification.';
$notificationService->sendAll($message);



    'check'             => [

        'active'        => true, // True Разрешить проверку или false Пропускать проверку
        'guard'         => 'web', // Укажите через какой гард будет работать

        'save_colum'    => 'id', // Поле для группы/роли или прав
        'save_value'    => [
            1, 2, 3
        ], // добавляем массив значений

    ],



    'logger_method'     => true,              // Использовать дефолтный вариант логирования(false - Кастомный логер)
    'logger_path'       => "logs/custom.log",  // Путь для кастомного логера