PHP code example of viicslen / laravel-alertable

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

    

viicslen / laravel-alertable example snippets


return [
    /**
     * The default model to use for alerts.
     */
    'model' => ViicSlen\LaravelAlertable\Models\Alert::class,

    /**
     * Connection settings to use for the default alerts model.
     */
    'database' => [
        /**
         * The connection to use. If left nulls, the default connection will be used.
         */
        'connection' => null,

        /**
         * The table to use. If left nulls, the default connection will be used.
         */
        'table' => null,
    ]
];



namespace App;

use Illuminate\Foundation\Auth\User as Authenticatable;
use ViicSlen\LaravelAlertable\Concerns\HasAlerts;
use ViicSlen\LaravelAlertable\Contracts\Alertable;

class User extends Authenticatable implements Alertable
{
    use HasAlerts;
}

use ViicSlen\LaravelAlertable\Enums\Severity;

// ...

$user = Auth::user();

$user->newAlert('This is a test alert', ['extra' => 'data'], Severity::Success);

$user = Auth::user();

// Get all alerts
$user->alerts()->get();

// Get alerts with a specific severity
$user->infoAlerts()->get();
$user->successAlerts()->get();
$user->warningAlerts()->get();
$user->errorAlerts()->get();

// Get latest alert
$user->latestAlert

use ViicSlen\LaravelAlertable\Enums\Severity;

// ...

// Delete all alerts
$user->clearAlerts()

// Delete alerts with a specific severity
$user->clearAlerts(Severity::Success)

// Delete alerts with a specific severity and category
$user->clearAlerts(Severity::Success, 'CATEGORY_1')
bash
php artisan vendor:publish --tag="alertable-migrations"
php artisan migrate
bash
php artisan vendor:publish --tag="alertable-config"