viicslen/laravel-alertable
Composer 安装命令:
composer require viicslen/laravel-alertable
包简介
This is my package laravel-alertable
README 文档
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.
统计信息
- 总下载量: 784
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-07