jalle19 / laravel-unshitty-flash
针对 Laravel 的高见性闪存消息服务
1.1.0
2017-04-05 19:06 UTC
Requires
- php: >= 7.0
- illuminate/http: ^5.4
- illuminate/support: ^5.4
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is auto-updated.
Last update: 2024-09-13 00:27:31 UTC
README
针对 Laravel 的高见性闪存消息服务。与我所见过的几乎所有其他类似库不同,这个
- 支持多条消息
- 支持多条相同消息
- 支持立即闪存,即当前请求
- 允许你配置使用的会话键
- 强制你注入服务,没有魔法外观
- 强制你直接操作
Request
对象
安装
安装包
composer require jalle19/laravel-unshitty-flash
注册服务提供者
'providers' => [ ... Jalle19\Laravel\UnshittyFlash\FlashServiceProvider::class, ... ]
发布配置文件
php artisan vendor:publish --provider="Jalle19\Laravel\UnshittyFlash\FlashServiceProvider"
用法
将 FlashService
注入你想要创建闪存消息的控制器中,然后像这样使用它
$this->flashService->success($request, 'Some successful message'); $this->flashService->info($request, 'Some informational message'); $this->flashService->warning($request, 'Some warning'); $this->flashService->danger($request, 'Some dangerous message');
如果你需要将消息闪存到当前请求中(例如,从显示永久消息的中介中),将 true
作为第三个参数传递
$this->flashService->info($request, 'Permanently visible message', true);
如果你需要的消息级别以上不足,你可以使用 message()
方法使用任意级别
$this->flashService->message($request, 'Some rant about libraries', 'rant');
要在视图中渲染闪存消息,你可以使用以下片段:
@foreach (session()->get(config('flash.session_key'), []) as $notification) <div class="alert alert-{{ $notification['level'] }} alert-dismissible in"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> {!! $notification['message'] !!} </div> @endforeach