dberry37388/laravel5-alerts

此包已被废弃,不再维护。未建议替代包。

用于管理Laravel 5应用程序中警报(消息)的包。

v0.0.1 2015-04-17 19:17 UTC

This package is not auto-updated.

Last update: 2023-01-21 08:42:44 UTC


README

用于管理Laravel 5应用程序中警报(消息)的包

安装

首先,让我们从composer中拉取这个包

composer require dberry37388/laravel5-alerts

Laravel集成

打开 app.php 文件,并将以下内容添加到 providers 数组中

"Dberry37388\Alerts\AlertsServiceProvider",

接下来,让我们添加外观。这将允许你进行诸如 Alerts::getErrors() 之类的操作。我们将将其添加到 aliases 数组中。

'Alerts'    => 'Dberry37388\Alerts\Facades\Alerts'

发布配置

你可以通过运行以下命令将默认配置发布到你的 app/config 目录:

php artisan vendor:publish --provider="Dberry37388\Alerts\AlertsServiceProvider" --tag=config

用法

添加新的警报。在这个例子中,我们添加了一个 "info" 警报。你可以用你需要的任何类型替换 "info"。

Alerts::error('my message');
Alerts::alert('info', 'Your Message Here');

向非默认容器添加警报

Alerts::error('My message', 'pnotify');
Alerts::alert('errors', 'My message here", "pnotify");

添加带有 "extra" 属性的警报。你可以按需使用额外的属性。例如,如果你想传递标题、图标类等,可以这样做。

Alerts::alert('info', 'My message here', null, ['icon' => 'fa fa-info', 'title' => 'Welcome!', 'timeout' => 4000]);

检索所有警报。

$alerts = Alerts::all();

检索特定类型的所有警报。你只需要在 "type" 前加上 get,例如要检索所有错误消息,或者使用完整的语法。

$errors = Alerts::getError();
$errors = Alerts::whereType('errors');

在特定容器中检索特定类型的所有警报,只需传递容器作为参数。

$alerts = Alerts::getError('pnotify');
$errors = Alerts::whereType('errors')->whereInContainer('pnotify');

你也可以检索所有不是特定类型的警报。你可以传递一个字符串或一个数组。

$errors = Alerts::notError('errors');
$errors = Alerts::whereNotType('errors');

容器

容器可以用来分组通知。例如,如果你想传递表单验证错误,可以有一个 "validation" 容器,或者如果你想使用javascript growl类型的通知显示某些通知,可以将这些分组到 "notifications" 容器中。

要检索特定容器中的所有警报,只需在容器名称前加上 "where"。

$alerts = Alerts::whereErrors();
$alerts = Alerts::whereInContainer('errors');

要检索具有特定类型的特定容器中的所有警报,只需传递类型作为参数。

$alerts = Alerts::whereNotification('info');
$alerts = Alerts::whereInContainer('errors')->whereType('info');

要检索不在特定容器中的所有警报。你可以传递一个字符串或一个数组。

$alerts = Alerts::whereNotInContainer('validation');