masterro / laravel-flashes
轻松使用闪存消息
v1.5.0
2024-03-22 14:08 UTC
Requires
- php: ^7.4|^8.0
- illuminate/session: ^5.1|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^5.1|^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^5.18|^6.17|^7.0|^8.0|^9.0
README
Laravel的轻松闪存消息
快速的闪存消息集成。
安装
在命令行中运行
composer require masterro/laravel-flashes
使用方法
在某个地方设置闪存消息
flash("Hello, {$name}!");flash("Hello, {$name}!", 'success');flash()->error($message);// ->success(), ->info(), ->warning(), ->error()flash()->with(['body' => 'My custom body text']);// ->success(), ->info(), ->warning(), ->error()Flash::info('Flash!');
在关闭 </body> 标签之前
@include('flash-messages::script')
或者 实现自己的渲染逻辑
php artisan vendor:publish --tag=flash-messages-views
实现通知方法(以bootstrap-notify为例)
包将触发全局javascript函数 window.notify(message, type),您应该实现它。以下是一个bootstrap-notify实现的示例
window.notify = (message, type = 'success', options = {}) => { if (type === 'error') { type = 'danger'; } return window.$.notify(window._.merge({ message: message }, options), { type: type, animate: { enter: 'animated bounceIn', exit: 'animated bounceOut' }, z_index: 9999, delay: 7000, mouse_over: 'pause', offset: { x: 20, y: 30 } }); };
它需要 bootstrap,bootstrap-notify 和 animate.css 您可以使用yarn或npm进行安装和引用
yarn add bootstrap-notify 或 npm i bootstrap-notify --save