PHP code example of scabarcas / laravel-notify-matrix

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

    

scabarcas / laravel-notify-matrix example snippets


use Illuminate\Foundation\Auth\User as Authenticatable;
use Scabarcas\LaravelNotifyMatrix\Concerns\HasNotificationPreferences;

class User extends Authenticatable
{
    use HasNotificationPreferences;
}

use Illuminate\Notifications\Notification;
use Scabarcas\LaravelNotifyMatrix\Attributes\NotificationGroup;

#[NotificationGroup('orders')]
class OrderShipped extends Notification
{
    public function via($notifiable): array
    {
        return ['mail', 'database'];
    }
}

$user->wants('orders', 'mail');                // true | false
$user->wants(OrderShipped::class, 'mail');     // resolves the group via the attribute
$user->setPreference('orders', 'mail', false);
$user->enable('orders', 'mail');
$user->disable('orders', 'mail');
$user->getPreferences();
$user->getPreferencesForGroup('orders');
$user->clearPreferences('orders');

return [
    'table' => 'notification_preferences',

    // Applied when no preference exists for a channel within a group.
    // Each group may override this below. Supported: "opt_in", "opt_out".
    'default_policy' => 'opt_in',

    'groups' => [
        'marketing' => [
            'default_policy' => 'opt_out',
        ],

        'security' => [
            'default_policy' => 'opt_in',
            'forced'         => ['mail'],
        ],
    ],

    'class_map' => [
        // Map notifications that cannot be annotated directly.
        // \Vendor\Pkg\Notifications\InvoicePaid::class => 'billing',
    ],

    'cache' => [
        'enabled' => true,
        'ttl'     => 300,
        'store'   => null,
    ],
];
bash
php artisan vendor:publish --tag=notify-matrix-config
php artisan vendor:publish --tag=notify-matrix-migrations
php artisan migrate