jeybin / toastr
php-flasher的简单助手
v1.0.3
2023-02-14 10:42 UTC
Requires
This package is auto-updated.
Last update: 2024-09-15 09:27:25 UTC
README
Toastr for Laravel是围绕流行的php-flasher库的包装,为在Laravel应用程序中显示通知提供了一个易于使用的接口。它包括服务提供者、外观和辅助函数,以简化在视图和控制器中使用Toastr。使用Laravel Toastr,您可以通过最少的配置轻松地在网站上显示toast消息。
要求
- PHP 7.2或更高版本
- Laravel 5.5或更高版本
安装
要安装Laravel Toastr,只需运行以下命令
composer require jeybin/toastr
安装包后,运行以下命令
php artisan toastr:install
这将复制配置文件到config/jeybin-toastr.php
用法
要在Laravel应用程序中使用Laravel Toastr,只需使用Toastr外观Jeybin\Toastr\Toastr来显示通知
\Jeybin\Toastr\Toastr::success('Your message here')->toast();
您还可以使用其他通知类型,如错误、警告和信息
\Jeybin\Toastr\Toastr::error('Your error message here')->toast(); \Jeybin\Toastr\Toastr::warning('Your warning message here')->toast(); \Jeybin\Toastr\Toastr::info('Your info message here')->toast();
另一种选择是将页面重定向到不同的页面并显示通知
$route变量可以是完整的URL、命名路由或为空/为null。如果为空或null,它将执行redirect()->back()并带有通知。
return \Jeybin\Toastr\Toastr::success('Hello world')->redirect($route);
config/jeybin-toastr.php文件使添加或修改重定向状态代码变得简单。或者,您可以使用以下语法提供状态代码:$statusCode必须是一个整数;默认值是302。
return \Jeybin\Toastr\Toastr::success('Hello world') ->redirectStatusCode($statusCode) ->redirect($route);
定制
Laravel Toastr支持自定义通知样式、位置、动画等。配置可以从config/jeybin-toastr.php进行更改
return [ /** * Time out in seconds */ 'timeout'=>1000, /** * show close button */ 'show_close_btn'=>true, /** * show progress bar */ 'show_progress_bar'=>true, /** * Prevent showing duplicate notifications */ 'prevent_duplicates'=>true, /** * Redirect status code default : 302 */ 'redirect_status_code'=>302 ];
或者您可以在函数调用时改变配置
\Jeybin\Toastr\Toastr::success('message') ->closeBtn(false) ->progressBar(false) ->preventDuplicates(false) ->rtl(true) ->timeOut(1500) ->toast();
- closeBtn(boolean) - 默认:true
- progressBar(boolean) - 默认:true
- preventDuplicates(boolean) - 默认:true
- rtl(boolean) - 默认:false
- timeOut(integer) - 默认:1000
- redirectStatusCode(integer) - 默认:302 如果您使用重定向函数,请使用
特性
- 易于安装和配置。
- 与Laravel 5.6及以上版本兼容。
- 高度可定制:更改样式、位置、动画等。
- 响应式:在所有设备和屏幕尺寸上工作。
- 轻量级:仅7kb压缩文件。
贡献
如果您想为Laravel Toastr做出贡献,请随时提交拉取请求或在GitHub页面上打开一个问题。
许可证
Laravel Toastr在MIT许可证下发布。