Laracasts / flash没有在laravel 5.4中显示

时间:2017-05-27 05:01:41

标签: laravel flash-message

我最近将我的项目从Laravel 5.1升级到5.4。除了没有显示的flash消息外,一切正常。我已经执行了以下检查以确保我没有做错事:

  1. RouteServiceProvider.php
  2. 通过mapWebRoutes函数

    将Web中间件组自动添加到我的路由中
    +--------+----------+-----+--------+------------------------------------------+--------------+
    | Domain | Method   | URI | Name   | Action                                   | Middleware   |
    +--------+----------+-----+---------------------------------------------------+--------------+
    |        | GET|HEAD | /   |        | App\Http\Controllers\HomeController@index| web,auth     |
    
    1. Kernel.php
    2. 以下是Kernel.php中的中间件组的内容

       'web' => [
                      \App\Http\Middleware\EncryptCookies::class,
                      \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
                      \Illuminate\Session\Middleware\StartSession::class,
                      // \Illuminate\Session\Middleware\AuthenticateSession::class,
                      \Illuminate\View\Middleware\ShareErrorsFromSession::class,
                      \App\Http\Middleware\VerifyCsrfToken::class,
                      \Illuminate\Routing\Middleware\SubstituteBindings::class,
                  ],
      
      1. 在重定向之前放置了flash()

        flash() - >成功(' Bob stone成功添加'); $ target_location =' cia_agent /' 。 $ agent_id。' /个人资料&#39 ;; return redirect($ target_location);

      2. Chrome in Chrome开发人员工具中只返回了一个302响应。

        以上代码适用于Laravel 5.1,我在这里缺少什么?

1 个答案:

答案 0 :(得分:1)

挖掘后,我找到了解决方案。在/resources/views/vendor/flash/message.blade.php中,我有以下代码适用于Laravel 5.1

@if (Session::has('flash_notification.message'))
    @if (Session::has('flash_notification.overlay'))
        @include('flash::modal', ['modalClass' => 'flash-modal', 'title' => Session::get('flash_notification.title'), 'body' => Session::get('flash_notification.message')])
    @else
        <div class="alert alert-{{ Session::get('flash_notification.level') }}">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>

            {{ Session::get('flash_notification.message') }}
        </div>
    @endif
@endif

但是由于Laracasts / flash视图部分用于显示消息的变化,我将新代码放在文件中:

@foreach ((array) session('flash_notification') as $message)
    @if ($message['overlay'])
        @include('flash::modal', [
            'modalClass' => 'flash-modal',
            'title'      => $message['title'],
            'body'       => $message['message']
        ])
    @else
        <div class="alert
                    alert-{{ $message['level'] }}
                    {{ $message['important'] ? 'alert-important' : '' }}"
             role="alert"
                >
            @if ($message['important'])
                <button type="button"
                        class="close"
                        data-dismiss="alert"
                        aria-hidden="true"
                        >&times;</button>
            @endif

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

{{ session()->forget('flash_notification') }}

现在工作得很好。