tjgazel/laravel-toastr
Composer 安装命令:
composer require tjgazel/laravel-toastr
包简介
Toastr notifications for laravel 5.5+, 6 and 7
README 文档
README
Other packages:
- tjgazel/laravel-bs4-alert - Bootstrap 4 alerts for laravel 5.*
- tjgazel/laravel-bs3-alert - Bootstrap 3 alerts for laravel 5.*
Installation
1) Install the Toastr library (front end dependency)
1.1) Install Toastr via npm . Github | Demo
npm install toastr --save-dev
1.2) Require the js in resources/assets/js/bootstrap.js as window.toastr = require('toastr');
try {
window.$ = window.jQuery = require('jquery');
require('bootstrap');
window.toastr = require('toastr');
} catch (e) { }
1.3) Import the sass in resources/assets/sass/app.scss as @import "~toastr/toastr"; then build via npm npm run prod.
// Fonts
@import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700");
// Variables
@import "variables";
// Bootstrap
@import "~bootstrap/scss/bootstrap";
// Toastr
@import "~toastr/toastr";
2) Install tjgazel/laravel-toastr
2.1) Run
composer require tjgazel/laravel-toastr
2.2) Optional: Laravel 5.4 and below
Add TJGazel\Toastr\ToastrServiceProvider::class to providers in config/app.php.
Add 'Toastr' => TJGazel\Toastr\Facades\Toastr::class to aliases in config/app.php.
// config/app.php
'providers' => [
// ...
TJGazel\Toastr\ToastrServiceProvider::class,
],
'aliases' => [
// ...
'Toastr' => TJGazel\Toastr\Facades\Toastr::class,
],
2.3) Run php artisan vendor:publish --provider="TJGazel\Toastr\ToastrServiceProvider"
to publish the config file in config/toastr.php
2.4) Add {!! Toastr::render() !!} Facade or {!! toastr()->render() !!} helper in your main view.
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="/css/app.css">
</head>
<body>
<div id="app"></div>
<script type="text/javascript" src="js/app.js"></script>
{!! toastr()->render() !!}
</body>
</html>
2.5) Optional: Modify the publish configuration file locate at config/toastr.php to your liking.
<?php
return [
'session_name' => 'toastr',
'options' => [
"closeButton" => true,
"debug" => false,
"newestOnTop" => false,
"progressBar" => true,
"positionClass" => "toast-bottom-right",
"preventDuplicates" => false,
"onclick" => null,
"showDuration" => "300",
"hideDuration" => "1000",
"timeOut" => "10000",
"extendedTimeOut" => "1000",
"showEasing" => "swing",
"hideEasing" => "linear",
"showMethod" => "fadeIn",
"hideMethod" => "fadeOut"
]
];
Usage
Use the Toastr facade Toastr:: or the helper function toast()-> to access the methods in this package.
Toastr::error(string $message, string $title = null, array $options = []);
toastr()->error(string $message, string $title = null, array $options = []);
Examples:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use TJGazel\Toastr\Facades\Toastr;
class DashboardController extends Controller
{
public function index()
{
Toastr::info('welcome admin!');
return view('dashoard.index');
}
}
You can also chain multiple messages together using:
toastr()
->error('Unauthorized!', 'Error 401')
->info('Authentication required to access dashboard page', null, ['timeOut' => 15000]);
Note that in the 3rd parameter you can customize toastr options. See the config/toastr.php file for all possibilities.
All methods
toastr()->info();
toastr()->warning();
toastr()->success();
toastr()->error();
Tanks for:
tjgazel/laravel-toastr 适用场景与选型建议
tjgazel/laravel-toastr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.95k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2018 年 05 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「notification」 「helper」 「laravel」 「facade」 「toastr」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tjgazel/laravel-toastr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tjgazel/laravel-toastr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tjgazel/laravel-toastr 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This package makes it easy to send notifications via AfricasTalking with Laravel
Datetime helpers for timezone handling
Library with classes to help you do batch.
Apple Push Notification & Feedback Provider
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
Throttle notifications on a per-channel basis
统计信息
- 总下载量: 12.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 7
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-18
