moddyx / laravel-notify
为 Laravel 提供灵活的闪存通知
Requires
- php: >=7.1
- illuminate/support: ~5.0|~6.0|~7.0
Requires (Dev)
- mockery/mockery: ^1.0
- phpunit/phpunit: ^8.0
This package is not auto-updated.
Last update: 2024-09-27 03:17:02 UTC
README
简介
Laravel Notify 是一个可以让您为项目添加自定义通知的包。提供多种通知设计,许多即将推出。
正在进行中
此包仍在积极开发中。如果您需要 Android 版本,请尝试此包 Aesthetic Dialogs。快乐编码 👨🏾💻
安装
您可以使用 composer 安装此包
$ composer require mckenziearts/laravel-notify
然后将服务提供者添加到 config/app.php。在 Laravel 5.5 及更高版本中,如果启用了包自动发现,可以跳过此步骤。
'providers' => [ ... Mckenziearts\Notify\LaravelNotifyServiceProvider::class ... ];
您可以通过运行以下命令发布配置文件和资产
$ php artisan vendor:publish --provider='Mckenziearts\Notify\LaravelNotifyServiceProvider'
现在我们已经将一些新文件发布到我们的应用程序中,我们需要使用以下命令重新加载它们
$ composer dump-autoload
用法
- 使用
@notifyCss添加样式链接 - 使用
@notifyJs添加脚本链接 - 在控制器内部使用
notify()辅助函数设置信息、成功、警告或错误的通知 - 将 notify 部分包含到主布局中
@include('notify::messages')
基本用法
在您的控制器中,在执行重定向调用之前,使用消息调用 notify 方法。
public function store() { notify()->success('Laravel Notify is awesome!'); return Redirect::home(); }
一个完整的例子
<!doctype html> <html> <head> <title>Laravel Notify</title> @notifyCss </head> <body> @include('notify::messages') @notifyJs </body> </html>
通知类型
Laravel Notify 实际上显示了 5 种类型的通知
toast通知,Laravel Notify 的默认通知
notify()->success('Welcome to Laravel Notify ⚡️')
connectify通知,基本使用示例
connectify('success', 'Connection Found', 'Success Message Here')
drakify(😎) 通知,仅用于显示警报
drakify('success') // for success alert or drakify('error') // for error alert
smilify通知,使用笑脸 😊 的简单自定义通知
smilify('success', 'You are successfully reconnected')
emotify通知,使用矢量表情符号的简单自定义通知
emotify('success', 'You are awesome, your data was successfully created')
预设通知
如果您有一个在系统中的多个不同位置使用的特定通知,您可以在配置文件中将它定义为预设通知。这使您可以在一个位置轻松维护常用通知。以下是如何在 配置 部分定义预设消息的说明。
例如,要使用名为 'common-notification' 的预设通知,请使用以下内容
notify()->preset('common-notification')
如果您需要覆盖配置中设置的任何值,可以这样做。例如,如果您有一个跨多个位置使用的通用通知,但想在特定位置更改图标,而不必手动编写新的通知,这可能很有用。
为此,只需传递一个包含您想覆盖的属性键及其值的数组的对象。
例如,我们可以通过以下方式覆盖 'common-notification' 的 'title':
notify()->preset('common-notification', ['title' => 'This is the overridden title'])
配置
配置文件位于发布提供者元素后 config/notify.php。
一些精彩的东西。要激活 暗黑模式,请更新 theme 配置,或在 .env 文件中添加全局变量 NOTIFY_THEME。
'theme' => env('NOTIFY_THEME', 'dark'),
结果如下
Laravel Notify 使用 animate.css 设置平滑的显示和隐藏通知元素动画。
/* |-------------------------------------------------------------------------- | Animate Module (use animate.css) |-------------------------------------------------------------------------- | | Use animate.css to animate the notice. | */ 'animate' => [ 'in_class' => 'bounceInRight', // The class to use to animate the notice in. 'out_class' => 'bounceOutRight', // The class to use to animate the notice out. 'timeout' => 5000 // Number of seconds before the notice disappears ],
您现在可以在配置文件中使用 position 变量选择通知应出现的位置。默认情况下,启用 top-right 位置。
'position' => 'top-right',
您可以使用以下结构在配置文件中定义预设通知
'preset-messages' => [ 'user-updated' => [ 'message' => 'The user has been updated successfully.', 'type' => 'success', 'icon' => 'flaticon2-check-mark', 'model' => 'connect', 'title' => 'User Updated', ], 'user-deleted' => [ 'message' => 'The user has been deleted successfully.', 'type' => 'success', 'icon' => 'flaticon2-check-mark', 'model' => 'connect', 'title' => 'User Deleted', ], ],
上面的例子显示了两个预设通知的配置:'user-updated' 和 'user-deleted'。
变更日志
有关最近更改的更多信息,请参阅变更日志。
贡献
有关详细信息以及待办事项列表,请参阅contributing.md。
安全性
如果您发现任何与安全相关的问题,请通过电子邮件联系作者,而不是使用问题跟踪器。
鸣谢
许可证
许可证。有关更多信息,请参阅许可证文件。