inpin / lara-alert
将 Alertable 特性添加到 Laravel Eloquent 模型
1.0.2
2018-06-13 11:21 UTC
Requires
- php: >=7.0
- illuminate/database: >=5.0
- illuminate/support: >=5.0
- laravel/framework: >=5.5
Requires (Dev)
- fzaninotto/faker: ~1.4
- mockery/mockery: ~1.0
- orchestra/database: ^3.5
- orchestra/testbench: ^3.5
- phpunit/phpunit: ~6.0
This package is auto-updated.
Last update: 2024-09-29 05:08:24 UTC
README
为 Laravel Eloquent 模型提供一个特性,以简化实现“用户警报”功能。
Composer 安装(适用于 Laravel 5.5 及以上版本)
composer require inpin/lara-alert
安装并运行迁移
'providers' => [ \Inpin\LaraAlert\LaraAlertServiceProvider::class, ],
php artisan vendor:publish --provider="Inpin\LaraAlert\LaraAlertServiceProvider" --tag=migrations
php artisan migrate
模型和数据库模式
它将为您创建一个包含以下字段的 laraalert_alerts
表
type
是警报的类型,例如:'警报','确认完成','软件更新'等。
description
是描述警报的可空文本。
seen_at
决定当前警报是否为新警报(seen_at 为 null_)或不是(seen_at 填充时间戳)。
设置您的模型
class Book extends \Illuminate\Database\Eloquent\Model { use Inpin\LaraAlert\Alertable; }
示例用法
// Create an alert with type of 'alert' by currently logged in user without description. $book->createAlert(); // Create a alert on $book object with type of "some-alert-type", and null description. $book->createAlert('some-alert-type'); // Create a alert on $book object with type of "some-alert-type", null description, // and current logged in user form 'api' guard as owner. $book->createAlert('some-alert-type', 'api'); // Create a alert on $book object with type of "some-alert-type", null description, and $user as owner. $book->createAlert('some-alert-type', $user); // Create a alert on $book object with type of "some-alert-type", with description of "some message, // and current logged in user form 'api' guard as owner. $book->createAlert('some-alert-type', 'api', 'some message'); // Create a alert on $book object with type of "some-alert-type", with description of "some message, // and current logged in user form 'api' guard as owner. $book->createAlert('some-alert-type', $user, 'some message'); // Create a alert on $book object with "alert item id" of 1 and 2, put user message of "some message on it", // and put $user (3rd param) as alerter. $book->createAlert([1, 2], 'some message', $user'); $book->alerts(); // HasMany relation to alerts of book. $book->alerts; // Collection of book's alerts. $book->isAlertedBy() // check if current logged in user form default guard has alerted book. $book->isAlertedBy('api') // check if current logged in user form 'api' guard has alerted book. $book->isAlertedBy($user) // check if '$user' has alerted book. $book->isAlerted() // check if $book has alert. $book->isAlerted // check if $book has alert. $book->alertsCount; // return number of alerts on $book. $book->alertsCount(); // return number of alerts on $book.
警报对象
// set seen_at with current timestamp. $alert->seen(); // check if $alert is new or not. $alert->isNew(); $alert->isNew; // check if $alert is seen or not. $alert->isSeen(); $alert->isSeen;
致谢
- Mohammad Nourinik - http://inpinapp.com