artdarek/toastr
Composer 安装命令:
composer require artdarek/toastr
包简介
Toastr - Flash Messages for Laravel 5
README 文档
README
Simple flash messagges system to use with Laravel 5 Framework. By default it relies on twitter bootstrap "alert" component. You can display multiple flash messages in different types (success, info, warning, danger) at once and to each message you can asign some custom params that will allow you for example mark some of them as important etc.
Installation
Via composer require command
Use composer require command to install this package.
$ composer require artdarek/toastr
Laravel version Compatibility
| Laravel | Package |
|---|---|
| 5.0.x | 1.0.x |
| 5.1.x | 1.0.x |
| 5.2.x | 2.0.x |
| 5.3.x | 2.0.x |
| 5.4.x | 2.0.x |
Adding package to composer.json file manually
Add package to your composer.json file:
"require": {
"artdarek/toastr": "2.0.*"
}
Use composer update command to install this package.
$ composer update
Registering the Package
Add the Toastr Service Provider to your config in config/app.php:
'providers' => array( Artdarek\Toastr\Providers\ToastrServiceProvider::class, ),
and create an alias:
'aliases' => [ 'Toastr' => Artdarek\Toastr\Facades\Toastr::class, ],
Usage
First of all you need to add some code to your view scripts. In most cases it will be layout file (or other place where you want to flash message be displayed). You can use default view script distrubuted within this package by adding following code into your view file:
@include('toastr::alerts')
or to gain more controll of the look and feel of your flash messages you can start with using following template (just copy and paste it into a place where your application allerts should be displayed):
@if(Session::has('toastr.alerts')) <div id="toastr"> @foreach(Session::get('toastr.alerts') as $alert) <div class='alert alert-{{ $alert['type'] }} @if(array_get($alert,'params.important') == true) important @endif'> <button class="close" type="button" data-dismiss="alert" aria-hidden="true">×</button> @if( ! empty($alert['title'])) <div><strong>{{ $alert['title'] }}</strong></div> @endif {{ $alert['message'] }} @if(array_get($alert,'params.important')) (This alert is marked as important) @endif </div> @endforeach </div> @endif
In your controllers/action before you perform a redirect:
public function login() { Toastr::success('Welcom back!')->push(); return Redirect::home(); }
you can push more than one alert at once:
public function login() { Toastr::success('Welcom back!')->push(); Toastr::warning('You don\'t look too good today!')->push(); return Redirect::home(); }
Other usage examples:
// using alert() method - first param is an alert type socond one is a message: Toastr::alert('danger','Error - generated by alert() method')->push(); Toastr::alert('danger','Error - generated by alert() method')->push(); Toastr::alert('info','Info - generated by alert() method')->push(); Toastr::alert('warning','Warning - generated by alert() method')->push(); Toastr::alert('success','Success - generated by alert() method')->push(); // error alert with title Toastr::alert('danger',['Some title','Error - generated by alert() method'])->push(); // succes Toastr::success('This is success')->push(); // success with title Toastr::success('Excelent','This is success')->push(); // info Toastr::info('That is just short info')->push(); // warning Toastr::warning('Thats a warning!')->push(); // error Toastr::danger('We got an error!')->push(); // adding additional params to each alert (with() method allows you to pass some custom params that can be used later in a view script) Toastr::danger('We got an error! And its marked as important')->with(['important' => true])->push(); Toastr::danger('We got an error!', 'But its not that important')->with(['important' => false])->push();
artdarek/toastr 适用场景与选型建议
artdarek/toastr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.67k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 09 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「alerts」 「toastr」 「laravel 5」 「flash messages」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 artdarek/toastr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 artdarek/toastr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 artdarek/toastr 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Toastr notifications for laravel 5.5+, 6 and 7
Add visual alerts / warnings to Flarum posts
Laravel package for managing session messages and alerts in view responses
Bootstrap alerts
Simple javascript toast notifications
Flexible Toastr Notifcation Package for PHP Laravel
统计信息
- 总下载量: 3.67k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-02