hepplerdotnet/flash-toastr

简易的 toastr.js 弹窗通知

5.6.1.1 2018-10-23 07:17 UTC

This package is auto-updated.

Last update: 2024-09-14 21:33:28 UTC


README

Latest Stable Version License Total Downloads

Flash Toastr

将 Laravel 的 Flash 消息转换为 Toastr.js

安装

首先,通过 Composer 引入包。

运行 composer require HepplerDotNet/flash-toastr

仅适用于 Laravel < 5.6

然后,在 config/app.php 中包含服务提供者。

'providers' => [
    HepplerDotNet\FlashToastr\FlashServiceProvider::class,
];

为了方便,可以在该文件的底部添加一个门面别名

'aliases' => [
    'Flash' => HepplerDotNet\FlashToastr\Flash::class,
];

使用方法

在您的控制器中,在执行重定向之前...

public function store()
{
    Flash::success('Welcome Aboard!','FlashToastr was successfully installed');

    return Redirect::home();
}

您也可以这样做

  • Flash::info('标题','消息')
  • Flash::success('标题','消息')
  • Flash::error('标题','消息')
  • Flash::warning('标题','消息')
  • Flash::notify('标题', '消息','级别')

这将设置会话中的几个键

  • 'flash_notification.title' - 您要闪现的消息标题
  • 'flash_notification.message' - 您要闪现的消息
  • 'flash_notification.level' - 表示通知类型的字符串(适用于应用 CSS/Bootstrap 类名)

或者,您可以参考 flash() 辅助函数,而不是门面。以下是一个示例

/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    flash()->success('Logout successfull','You have been logged out.');

    return home();
}

您甚至可以将它们链接起来一次闪现多条消息。

/**
 * Destroy the user's session (logout).
 *
 * @return Response
 */
public function destroy()
{
    Auth::logout();

    flash()->success('Logout successfull','You have been logged out.')
    ->warning('Close Browser','You should close this Browser window now');

    return home();
}

将这些消息闪现到会话中后,您现在可以在视图(s)中显示它。

@include('flash-toastr::message')

这将包含 message.blade.php 到您的视图中。

如果您需要修改闪现消息的片段,可以运行

php artisan vendor:publish --tag=flash-views

消息视图现在位于 resources/views/vendor/flash-toastr/ 目录。

toastr.js 的 JavaScript 选项

您可以通过传递一个选项数组来设置 toastr.js

{{ Config::set('flash-toastr.options', ['progressBar' => false,'positionClass' => 'toast-top-left']) }}

您还可以发布配置文件

php artisan vendor:publish --tag=flash-config

要发布配置和视图,可以运行

php artisan vendor:publish --tag=flash

有关所有可用选项,请参阅 Toastr 文档