【问题标题】:Laracasts/flash not showing in laravel 5.4laravel 5.4 中未显示 Laracasts/flash
【发布时间】:2017-05-27 05:01:41
【问题描述】:

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

  1. RouteServiceProvider.php

web 中间件组通过 mapWebRoutes 函数自动添加到我的路由中

+--------+----------+-----+--------+------------------------------------------+--------------+
| Domain | Method   | URI | Name   | Action                                   | Middleware   |
+--------+----------+-----+---------------------------------------------------+--------------+
|        | GET|HEAD | /   |        | App\Http\Controllers\HomeController@index| web,auth     |
  1. 内核.php

下面是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()->success('Bob Stone 添加成功'); $target_location = 'cia_agent/' 。 $agent_id .'/profile'; 返回重定向($target_location);

Chrome 开发者工具的 Network 中只返回一个 302 响应。

上面的代码在 Laravel 5.1 中工作,我在这里缺少什么?

【问题讨论】:

标签: laravel flash-message


【解决方案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 view partial 发生了变化,我将新代码放在文件中:

@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') }}

现在运行良好。

【讨论】:

    猜你喜欢
    • 2016-06-14
    • 2017-07-29
    • 2017-09-25
    • 2018-08-29
    • 1970-01-01
    • 1970-01-01
    • 2018-03-03
    • 2017-09-10
    • 2018-11-05
    相关资源
    最近更新 更多