bkstar123 / flashing
一个轻量级的Laravel应用发送闪存消息的包。此包一次只支持一个闪存消息,并且消息以吐司通知的形式显示
Requires
- php: ^7.1.3
This package is auto-updated.
Last update: 2024-09-22 19:56:04 UTC
README
一个轻量级的Laravel应用发送闪存消息的包。此包一次只支持一个闪存消息,并且消息以吐司通知的形式显示
1. 要求
- PHP 7.1.3+
- Laravel 5.5+
2. 安装
composer require bkstar123/flashing
之后,您需要发布包的资产
php artisan vendor:publish --provider="Bkstar123\Flashing\FlashingServiceProvider"
它将复制一个blade视图元素到您的应用resources/views/vendor/bkstar123_flashing/flashing.blade.php。您可以根据需要自定义此视图元素。此外,它还将包的JavaScript文件复制到您的应用的public/js/vendor/bkstar123)handling/*.js
3. 使用
a) 在视图中
在视图或主布局中,只需使用@include('bkstar123_flashing::flashing')包含包的视图元素
b) 在控制器方法中
默认情况下,该包为您提供了以下工具集用于发送消息
Bkstar123\Flashing\Facades\FlashingFacade。或者,您可以使用其别名Flashingflashing()辅助函数
该包支持以下类型的闪存消息
- 成功
- 错误
- 警告
- 信息 (默认)
示例:
<?php // Flash a info-typed message by default \Flashing::message('Welcome to the home page') ->flash(); flashing('Welcome to the home page') ->flash(); // Flash a success-typed message \Flashing::message('Welcome to the home page') ->success() ->flash(); flashing('Welcome to the home page') ->success() ->flash(); // Flash a message and mark it as important i.e it will not disappear until being dismissed by yourself \Flashing::message('Important message') ->important() ->flash(); flashing('Important message') ->important() ->flash(); // Specify the miliseconds for timing out the flash message // The given timeout will be ignored if you mark the flash message as important \Flashing::message('This message will disappear after 3 seconds') ->timeout(3000) ->flash(); flashing('This message will disappear after 3 seconds') ->timeout(3000) ->flash(); // Specify the location of the flash message, it can be either top-right or bottom-right \Flashing::message('I will be on the top-right of your screen') ->position('top') ->flash(); flashing('I will be on the top-right of your screen') ->position('top') ->flash();
所有方法 success() | error() | warning() | info() 都可以在message()之后链式使用,也可以通过important(), timeout() & position()链式使用。最终,您必须始终将flash()追加到链中。
注意: flashing('hello world') <=> \Flashing::message('hello world')