felixl7/laravel-bootstrap-toast
Composer 安装命令:
composer require felixl7/laravel-bootstrap-toast
包简介
This is a simple Bootstrap Toast Package for Laravel.
README 文档
README
This is a simple Bootstrap Toast Package for Laravel.
Installation
composer require felixl7/laravel-bootstrap-toast
You can optionally publish the config file, public resources and blade templates of this package:
php artisan vendor:publish --provider="FelixL7\Toast\ToastServiceProvider"
Setup
Just @include('bootstrap-toast::toaster') into your layout template and make sure to include jQuery and Bootstrap.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
This package also uses FontAwesome, but you're free to remove it or add your favourite icon package. Just publish the views of this package and replace the icons from the toast type templates.
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/css/all.min.css">
Usage
It's really simple to create Toasts. Just
use FelixL7\Toast\Models\Toast; ... Toast::default('Toast Title', 'Your Message'); Toast::success('Toast Title', 'Your Message'); Toast::info('Toast Title', 'Your Message'); Toast::warning('Toast Title', 'Your Message'); Toast::error('Toast Title', 'Your Message');
wherever you want. Or if you return a redirect in your controller:
return redirect()->with('toasts', [Toast::success('Toast Title', 'Your Message')]);
Config
You can customize the toast via the config file. Just publish the packages configuration und edit the bootstrap-toast.php file in your config folder.
php artisan vendor:publish --provider="FelixL7\Toast\ToastServiceProvider" --tag=config
Custom Toasts
If you want to create some custom toasts, you just have to publish the views of this package. There you have a toasts folder. Here you can create your own toast types. You can call them by
Toast::custom('Toast Title', 'Your Message', 'your-type');
'your-type' must be identical with your custom toast template name.
You can customize the design of the toasts by adding css. If you want to use the default styles, you just have to publish the css by
php artisan vendor:publish --provider="FelixL7\Toast\ToastServiceProvider" --tag=public
Validation Error Toast
If you want to use Toasts in your custom FormRequest you just need to ad this method:
/** * Handle a failed validation attempt. * * @param \Illuminate\Contracts\Validation\Validator $validator * @return void * * @throws \Illuminate\Http\Exceptions\HttpResponseException */ protected function failedValidation(Validator $validator) { throw new HttpResponseException( redirect()->back() ->withInput($this->except($this->dontFlash)) ->withErrors($validator) ->with('bootstrap-toasts', [Toast::error('Validation Error', 'The validation of your input failed. Please checkout the validation messages.')]) ); }
Links
Contact
Any Questions or improvement suggestions? Contact me! info@felixlipinski.de
felixl7/laravel-bootstrap-toast 适用场景与选型建议
felixl7/laravel-bootstrap-toast 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 424 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 05 月 23 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 felixl7/laravel-bootstrap-toast 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 felixl7/laravel-bootstrap-toast 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 424
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-23