承接 zaichaopan/flash 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

zaichaopan/flash

Composer 安装命令:

composer require zaichaopan/flash

包简介

A simple package to make flash message more flexible

README 文档

README

This package makes Laravel flash message more flexible. It can be used in laravel 5.5 or higher.

Installation

composer require zaichaopan/flash

Usage

In laravel, you can flash message like below

$request->session()->flash($key, $message);

Or you can use the with method when redirect

// in your controller action method
return redirect()->with($key, $message);

// or take advantage of dynamically binding
return redirect()->withSuccess($message); // or withError, withWarning, ...

But the problem is when it comes to showing flash message in blade, your flash message may have different keys (e.g. error, success, ...). You have to check all the possible keys to determine if you have flash message to show in the blade. This package can be used to make things easier.

  • To flash a message

This packages provides a global helper method flash to create a Flash instance. After you create the Flash instance, there are five available methods you can call to generate five different types of flash messages. Each method takes two parameters: message and options.

The first one is required which is used to set the message body of the flash. The second one is an array and it is optional. It is used to add addition data to the flash.

// generate a general info message
flash()->info($message, $options) ;

// generate a success message
flash()->success($message, $options);

// generate a warning message
flash()->warning($message, $options);

// generate a danger message
flash()->danger($message, $options);

// generate an error message
flash()->error($message, $options);
  • Check whether flash exists:
<!-- your blade -->
@if (flash()->ready())
<!-- your flash html -->
@endif
  • Get flash type:
flash()->type();
  • Get flash message
flash()->message();
  • Get additional option data
flash()->options();
  • Pass data to javascript

In real life, you may want to create a flash component in vue, which can be used to display the flash message from the server or from the js. To do that, let's say you have a component called Flash.vue and there is a property called flash inside it.

<Flash :flash={{ json_encode(flash()) }}></Flash>

Now if there is no flash, the value of the flash property will be null. If there is a flash message, the value will be an object contains properties: message, type, options.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-06-21

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固