PHP code example of simianbv / notifications

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

    

simianbv / notifications example snippets


return [
    // Middleware applied to the subscription routes
    'middleware' => ['api'],

    // Optional route prefix (e.g. 'api/v1')
    'route_prefix' => '',

    // The model used for subscribers
    'employee_model' => \App\Models\Employee::class,
];

use Simianbv\Notifications\Facades\NotificationBroker;

// Notify all subscribers of a type
NotificationBroker::notify('Refund', $refund, 'Terugbetaling verwerkt.');

// With a link
NotificationBroker::notify('Refund', $refund, 'Terugbetaling verwerkt.', '/finance/refunds/42');

// With extra data
NotificationBroker::notify('Order', $order, 'Order verzonden.', '/sales/orders/123', ['status' => 'shipped']);

// Type-only, no specific entity
NotificationBroker::notify('BankImport', null, 'Nieuwe bankimport verwerkt.');

use Simianbv\Notifications\Notifications\SubscriptionNotification;

SubscriptionNotification::resolveMessageUsing('Refund', function ($refund, $data) {
    return "Refund #{$refund->getKey()} van {$refund->amount} is verwerkt.";
});

SubscriptionNotification::resolveLinkUsing('Refund', function ($refund, $data) {
    return "/finance/refunds/{$refund->getKey()}";
});

NotificationBroker::notify('Refund', $refund);
bash
php artisan vendor:publish --tag=notifications-migrations
php artisan migrate
bash
php artisan vendor:publish --tag=notifications-config