search-flyer / flash-notifications
为Laravel提供优雅的Flash通知
v0.1.5
2017-09-01 21:15 UTC
README
Laravel 5 flash通知,最初是在Laracasts视频教程优雅的Flash消息之后开发的,该教程使用了SweetAlert。
快速安装
运行以下命令通过Composer安装包。
composer require srmklive/flash-notifications
或在您的composer.json文件中添加 "search-flyer/flash-notifications": ">=0.1"
然后运行
composer update
一旦此操作完成,只需将服务提供者和外观类添加到您的项目config/app.php
文件中
服务提供者
'Srmklive\FlashAlert\FlashAlertServiceProvider', // Laravel 5.0 Srmklive\FlashAlert\FlashAlertServiceProvider::class, // Laravel 5.1 or greater
外观
'FlashAlert' => 'Srmklive\FlashAlert\Facades\FlashAlert', // Laravel 5.0 'FlashAlert' => Srmklive\FlashAlert\Facades\FlashAlert::class, // Laravel 5.1 or greater
发布配置和视图
php artisan vendor:publish
用法
只需调用FlashAlert
来设置所需的Flash通知。有几种方法可以分配不同级别的优先级(信息、成功、警告和错误)。
成功
FlashAlert::success('Success', 'This is a success message.');
信息
FlashAlert::info('Info', 'This is an info message.');
警告
FlashAlert::warning('Warning', 'This is a warning message.');
错误
FlashAlert::error('Error', 'This is an error message.');
渲染
要在视图中渲染您的Flash通知,只需在主布局中包含视图部分。同时,在主布局中添加 @yield('styles') 和 yield('scripts')
@include('flashalert::alert')