viicslen / laravel-alertable
This is my package laravel-alertable
v1.1.0
2024-10-24 13:06 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^10.0|^11.0
- spatie/laravel-package-tools: ^1.14.2
Requires (Dev)
- laravel/pint: ^0.2.3
- nunomaduro/collision: ^7.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- spatie/laravel-ray: ^1.26
This package is auto-updated.
Last update: 2024-11-24 13:24:13 UTC
README
This is a simple package to add alerts to your laravel models.
Installation
You can install the package via composer:
composer require viicslen/laravel-alertable
You can publish and run the migrations with:
php artisan vendor:publish --tag="alertable-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --tag="alertable-config"
This is the contents of the published config file:
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, ] ];
Usage
First define any model as alertable by adding the HasAlerts
trait to your model (and optionally the Alertable
interface):
<?php 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; }
Create an alert:
use ViicSlen\LaravelAlertable\Enums\Severity; // ... $user = Auth::user(); $user->newAlert('This is a test alert', ['extra' => 'data'], Severity::Success);
Retrieve alerts:
$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
Delete alerts:
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')
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.