viicslen/laravel-alertable

这是我的包 laravel-alertable

v1.0.0 2023-09-19 13:45 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

这是一个简单的包,用于向您的 Laravel 模型添加警报。

安装

您可以通过 composer 安装此包

composer require viicslen/laravel-alertable

您可以使用以下命令发布并运行迁移

php artisan vendor:publish --tag="alertable-migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="alertable-config"

这是已发布配置文件的内容

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,
    ]
];

用法

首先,通过向您的模型添加 HasAlerts 特性(以及可选的 Alertable 接口)来定义任何模型为可警报

<?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;
}

创建警报

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')

测试

composer test

变更日志

有关最近更改的更多信息,请参阅 变更日志

贡献

有关详细信息,请参阅 贡献指南

安全漏洞

有关如何报告安全漏洞的详细信息,请参阅 我们的安全策略

鸣谢

许可

MIT 许可证(MIT)。有关更多信息,请参阅 许可文件