artdarek/toastr 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

artdarek/toastr

最新稳定版本:2.0.0

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">&times;</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();

统计信息

  • 总下载量: 3.67k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-09-02