kessam/toastr
Composer 安装命令:
composer require kessam/toastr
包简介
toastr.js flush notifications for Laravel
关键字:
README 文档
README
👀 This package helps you to add toastr.js notifications to your Laravel projects.
Install
You can install the package using composer
composer require Kessam/toastr
Usage:
The usage of this package is very simple and straightforward. it only required one step to use it :
Use toastr() helper function inside your controller to set a toast notification for info, success, warning or error
// Display an error toast with no title toastr()->error('Oops! Something went wrong!');
As an example:
<?php namespace App\Http\Controllers; use App\Post; use App\Http\Requests\PostRequest; use Illuminate\Database\Eloquent\Model; class PostController extends Controller { public function store(PostRequest $request) { $post = Post::create($request->only(['title', 'body'])); if ($post instanceof Model) { toastr()->success('Data has been saved successfully!'); return redirect()->route('posts.index'); } toastr()->error('An error has occurred please try again later.'); return back(); } }
Other Options
// Set a warning toast, with no title toastr()->warning('Are you sure you want to proceed ?'); // Set a success toast, with a title toastr()->success('Data has been saved successfully!', 'Congrats'); // Set an error toast, with a title toastr()->error('Oops! Something went wrong!', 'Oops!'); // Override global config options from 'config/toastr.php' toastr()->success('Data has been saved successfully!', 'Congrats', ['timeOut' => 5000]);
Other api methods:
You can also chain multiple messages together using method chaining
toastr() ->info('Welcome back') ->success('Data has been saved successfully!') ->warning('Are you sure you want to proceed ?');
You can use toastr('') instead of toastr()->success()
function toastr(string $message = null, string $type = 'success', string $title = '', array $options = []);
So
toastr($message)is equivalent totoastr()->success($message)toastr($message, 'info')is equivalent totoastr()->info($message)toastr($message, 'warning')is equivalent totoastr()->warning($message)toastr($message, 'error')is equivalent totoastr()->error($message)
configuration:
As optional if you want to modify the default configuration, you can publish the configuration file:
php artisan vendor:publish --provider="Kessam\Toastr\ToastrServiceProvider"
// config/toastr.php <?php return [ /* |-------------------------------------------------------------------------- | Toastr options |-------------------------------------------------------------------------- | | Here you can specify the options that will be passed to the toastr.js | library. For a full list of options, visit the documentation. | */ 'options' => [ 'closeButton' => true, 'closeClass' => 'toast-close-button', 'closeDuration' => 300, 'closeEasing' => 'swing', 'closeHtml' => '<button><i class="icon-off"></i></button>', 'closeMethod' => 'fadeOut', 'closeOnHover' => true, 'containerId' => 'toast-container', 'debug' => false, 'escapeHtml' => false, 'extendedTimeOut' => 10000, 'hideDuration' => 1000, 'hideEasing' => 'linear', 'hideMethod' => 'fadeOut', 'iconClass' => 'toast-info', 'iconClasses' => [ 'error' => 'toast-error', 'info' => 'toast-info', 'success' => 'toast-success', 'warning' => 'toast-warning', ], 'messageClass' => 'toast-message', 'newestOnTop' => false, 'onHidden' => null, 'onShown' => null, 'positionClass' => 'toast-top-right', 'preventDuplicates' => true, 'progressBar' => true, 'progressClass' => 'toast-progress', 'rtl' => false, 'showDuration' => 300, 'showEasing' => 'swing', 'showMethod' => 'fadeIn', 'tapToDismiss' => true, 'target' => 'body', 'timeOut' => 5000, 'titleClass' => 'toast-title', 'toastClass' => 'toast', ], ];
For a list of available options, see toastr.js' documentation.
Credits
License
MIT
kessam/toastr 适用场景与选型建议
kessam/toastr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「php」 「javascript」 「laravel」 「toastr」 「rtl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 kessam/toastr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 kessam/toastr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 kessam/toastr 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
The bundle for easy using json-rpc api on your project
PHP client for the Google Closure Compiler API in one file.
Yii2 integration for AirBnB Polyglot.js
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-04
