定制 grimthorr/laravel-toast 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

grimthorr/laravel-toast

最新稳定版本:1.1.2

Composer 安装命令:

composer require grimthorr/laravel-toast

包简介

Simple toast messages for Laravel 5.

README 文档

README

Simple toast messages for Laravel 5.

Warning

This repository has been archived. It is no longer maintained and can be considered abandoned. While it may work with later versions of Laravel, you should exercise caution while using it to avoid introducing any unexpected security risks.

Installation

1. Run composer require grimthorr/laravel-toast to include this in your project.

2. Optional, Laravel 5.4 and below: Add 'Grimthorr\LaravelToast\ServiceProvider' to providers in config/app.php, and add 'Toast' => 'Grimthorr\LaravelToast\Facade' to aliases in config/app.php.

// config/app.php
'providers' => array(
  // ...
  'Grimthorr\LaravelToast\ServiceProvider',
),
// ...
'aliases' => array(
  // ...
  'Toast' => 'Grimthorr\LaravelToast\Facade',
),

3. Include @include('toast::messages') or @include('toast::messages-jquery') somewhere in your template.

4. Optional: Run php artisan vendor:publish --provider="Grimthorr\LaravelToast\ServiceProvider" --tag="config" to publish the config file.

5. Optional: Modify the published configuration file located at config/laravel-toast.php to your liking.

6. Optional: Run php artisan vendor:publish --provider="Grimthorr\LaravelToast\ServiceProvider" --tag="views" to publish the views.

7. Optional: Modify the published views located at resources/views/vendor/toast to your liking.

Configuration

Pop open config/laravel-toast.php to adjust package configuration. If this file doesn't exist, run php artisan vendor:publish --provider="Grimthorr\LaravelToast\ServiceProvider" --tag="config" to create the default configuration file.

return array(
  'levels' => array(
    'info' => 'info',
    'success' => 'success',
    'error' => 'error',
    'warning' => 'warning',
    'default' => 'info'
  ),
);

Levels

Specify the class sent to the view for each level. For example calling the info method would send the info class to the view. If you use Bootstrap, you could set this to alert alert-info for ease of use in the view.

You can create a custom method here by passing a new level name and class. For example: 'help' => 'help' will allow you to call Toast::help($message). Alternatively, you can use the Toast::message($message, $level) method instead.

Views

This package includes a couple of views to get you started, they can be published to your resources directory using php artisan vendor:publish --provider="Grimthorr\LaravelToast\ServiceProvider" --tag="views" or called straight from the package by including them in a Blade template: @include('toast::messages').

@if(Session::has('toasts'))
  @foreach(Session::get('toasts') as $toast)
    <div class="alert alert-{{ $toast['level'] }}">
      <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

      {{ $toast['message'] }}
    </div>
  @endforeach
@endif

Usage

Use the Toast facade (Toast::) or the helper function (toast()->) to access the methods in this package. You can also chain multiple messages together using method chaining: toast()->success('done')->info('hello'). The title argument is optional.

Message

Toast::message('message', 'level', 'title');
toast()->message('message', 'level', 'title');
toast('message', 'title');

Add a toast to the session. Using toast('message') will use the default level.

Info

Toast::info('message', 'title');
toast()->info('message', 'title');

Add a toast with the info level.

Success

Toast::success('message', 'title');
toast()->success('message', 'title');

Add a toast with the success level.

Error

Toast::error('message', 'title');
toast()->error('message', 'title');

Add a toast with the error level.

Warning

Toast::warning('message', 'title');
toast()->warning('message', 'title');

Add a toast with the warning level.

Clear

Toast::clear();
toast()->clear();

Remove all pending toast messages from the session.

Example

These examples are using the default configuration.

Using the facade to send an error message

The following adds an error toast to the session and then redirects to home.

// Create the message
Toast::error('oops');

// Return a HTTP response to initiate the new session
return Redirect::to('home');

Using method chaining to create multiple toasts

The following adds an error and info toast to the session and then redirects to home.

// Create the message
Toast::error('oops')
  ->info('hello');

// Return a HTTP response to initiate the new session
return Redirect::to('home');

Using the helper function to send a message with a title

The following adds a toast to the session and then redirects to home.

// Create the message
toast('example', 'title goes here');

// Return a HTTP response to initiate the new session
return Redirect::to('home');

Using the helper function to send a message with a custom level

The following adds a help toast to the session and then redirects to home.

// Create the message
toast()->message('example', 'help');

// Return a HTTP response to initiate the new session
return Redirect::to('home');

Finally

Contributing

Feel free to create a fork and submit a pull request if you would like to contribute.

Bug reports

Raise an issue on GitHub if you notice something broken.

Credits

Based loosely on https://github.com/laracasts/flash.

grimthorr/laravel-toast 适用场景与选型建议

grimthorr/laravel-toast 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 72.39k 次下载、GitHub Stars 达 43, 最近一次更新时间为 2015 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 grimthorr/laravel-toast 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 grimthorr/laravel-toast 我们能提供哪些服务?
定制开发 / 二次开发

基于 grimthorr/laravel-toast 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 43
  • Watchers: 7
  • Forks: 22
  • 开发语言: PHP

其他信息

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