narutimateum/toastr-5.2-laravel

此包已被废弃且不再维护。未建议替代包。

为 Laravel 5.2 提供的 toastr.js,易于使用的通知,例如 growl 。

此包的官方仓库似乎已消失,因此该包已被冻结。

dev-master 2016-01-30 12:10 UTC

This package is not auto-updated.

Last update: 2024-09-25 21:52:14 UTC


README

toastr.js for Laravel 5.2

Bower

通过 Bower 安装插件,请运行

bower install toastr

###1 链接至 toastr.css <link href="toastr.css" rel="stylesheet"/>

###2 链接至 toastr.js <script src="toastr.js"></script>

安装

  1. 运行 composer require narutimateum/toastr-5.2-laravel 或在 composer.json 中的 require 键中添加 "narutimateum/toastr-5.2-laravel": "dev-master",然后运行 composer install

  2. 'narutimateum\Toastr\ToastrServiceProvider', 添加到 config/app.php 中的 providers

  3. 'Toastr' => 'narutimateum\Toastr\Facades\Toastr', 添加到 config/app.php 中的 aliases

用法

在您的母版视图模板中包含 jQuery、toastr.js 和插件样式

完成后做

{!! Toastr::render() !!}

在模板中,在 body 结束标签之前或.toastr.js 脚本实例化之后。

您可以在控制器中使用以下方法来插入一个 toast

  • Toastr::warning($message, $title = null, $options = []) - 添加一个警告 toast
  • Toastr::error($message, $title = null, $options = []) - 添加一个错误 toast
  • Toastr::info($message, $title = null, $options = []) - 添加一个信息 toast
  • Toastr::success($message, $title = null, $options = []) - 添加一个成功 toast
  • Toastr::add($type: warning|error|info|success, $message, $title = null, $options = []) - 添加一个 toast
  • Toastr::clear() - 清除所有当前 toast 请务必使用它

设置自定义 Toastr 选项

您可以设置 Toastr 的自定义选项。运行

php artisan vendor:publish

以发布 Toastr 的配置文件。然后编辑 config/toastr.php 并将 options 数组设置为您想传递给 Toastr 的任何内容。这些选项作为默认选项设置,可以通过在 用法 部分中的任何方法中传递选项数组来覆盖。

###例如###

<?php

return [
    'options' => 
    ["progressBar" => true,
    "positionClass" =>"toast-bottom-right",
    "preventDuplicates"=> false,
    "showDuration" => 300,
    "hideDuration" => 1000,
    "timeOut" => 5000,
    "extendedTimeOut" => 1000,
    "showEasing" => "swing",
    "hideEasing"=> "linear",
    "showMethod" => "fadeIn",
    "hideMethod" => "fadeOut"]
    ];
    

有关可用选项的列表,请参阅 toastr.js 文档