geekghc/flash

laravel 的 flash

安装: 70

依赖: 0

建议者: 0

安全: 0

星标: 8

关注者: 2

分支: 4

开放问题: 0

语言:HTML

2.8 2017-04-14 08:41 UTC

This package is not auto-updated.

Last update: 2024-09-29 01:02:27 UTC


README

Build Status Scrutinizer Code Quality

介绍

基于 Jeffery Way 的 Flash 包

预览

1.gif 2.gif

安装

使用composer安装

composer require geekghc/flash

或者在您的composer.json中在require部分添加

"geekghc/flash":"~2.0"

下载完成后,在config/app.php中添加service provider

'providers' => [
    GeekGhc\LaraFlash\FlashProvider::class,
];

为了方便使用,还可以添加一个alias

'aliases' => [
    'LaraFlash'=>GeekGhc\LaraFlash\Flash::class,
];

用法

在控制器中,在重定向之前

public function store()
{
    LaraFlash::success("Welcome Aboard!");

    return Redirect::home();
}

在视图中添加notification视图

@include('laraflash::notification')

或者

@include('laraflash::header-notification')

您也可以使用以下形式

  • LaraFlash::success('消息')
  • LaraFlash::info('消息')
  • LaraFlash::error('消息')
  • LaraFlash::warning('消息')

当然,您也可以使用laraflash()这样的helper function

  • laraflash('消息!') 默认为info
  • laraflash()->success('消息!')
  • laraflash()->info('消息!')
  • laraflash()->error('消息!')
  • laraflash()->warning('消息!')

例子

在此之前使用CDN形式引入jqueryfont-awesome

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Laravel</title>
    <link href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
</head>
<body>
<script src="//cdn.bootcss.com/jquery/2.1.0/jquery.min.js"></script>
@include('laraflash::notification')
</body>
</html>

自定义样式

您可以根据需求修改样式

php artisan vendor:publish

这样视图文件将放在您的resources/views/vendor/laraFlash目录下