承接 viicslen/laravel-alertable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

viicslen/laravel-alertable

Composer 安装命令:

composer require viicslen/laravel-alertable

包简介

This is my package laravel-alertable

README 文档

README

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

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-07