kamaln7 / toastr
此包已被弃用且不再维护。未建议替代包。
Laravel 4 的简单 toastr 通知
dev-master
2015-01-17 19:57 UTC
Requires
- php: >=5.3.0
- illuminate/session: >=4.0.0
- illuminate/support: >=4.0.0
This package is not auto-updated.
Last update: 2020-01-20 03:23:31 UTC
README
Laravel 4 的简单 toastr.js 通知
安装
- 运行
composer require kamaln7/toastr dev-master或将"kamaln7/toastr": "dev-master"添加到composer.json中的require键,然后运行composer install - 将
'Kamaln7\Toastr\ToastrServiceProvider',添加到app/config/app.php中的providers键 - 将
'Toastr' => 'Kamaln7\Toastr\Facades\Toastr',添加到app/config/app.php中的aliases键
使用方法
在您的 master 视图模板中包含 jQuery 和 toastr.js,然后在 Toastr::render() 的输出之后
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/toastr.js/2.0.0/js/toastr.min.js"></script> {{ Toastr::render() }}
在您的控制器中调用以下方法之一以插入一个 toasts
Toastr::warning($message, $title = null, $options = [])- 添加一个警告 toastsToastr::error($message, $title = null, $options = [])- 添加一个错误 toastsToastr::info($message, $title = null, $options = [])- 添加一个信息 toastsToastr::success($message, $title = null, $options = [])- 添加一个成功 toastsToastr::add($type: warning|error|info|success, $message, $title = null, $options = [])- 添加一个 toastsToastr::clear()- 清除所有当前 toasts
设置自定义 Toastr 选项
您可以为 Toastr 设置自定义选项。运行
php artisan config:publish kamaln7/toastr
发布 Toastr 的配置文件。然后编辑 app/config/packages/kamaln7/toastr/config.php 并将 options 数组设置为要传递给 Toastr 的任何内容。这些选项作为默认选项设置,并且可以在“使用方法”部分的任何方法中通过传递选项数组来覆盖。
有关可用选项的列表,请参阅 toastr.js 的文档。