dousuiguang9328 2016-04-29 08:25
浏览 56

会话闪存不起作用,放了[L5.2]

Pretty basic things going on. Using Session Flash messages to display any success/error messages.

All routes are set-up in my 'middleware' => 'web' group.

Now my problem. ->flash() does not work whilst ->put() does.

Controller:

$request->session()->flash('alert-success', 'My flash message');

Blade:

@foreach (['danger', 'warning', 'success', 'info'] as $msg)
    @if(Session::has('alert-' . $msg))
        <p class="alert alert-{{ $msg }}">{{ Session::get('alert-' . $msg) }} <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
        </p>
    @endif
@endforeach

The return redirect('routeHere')->with('alert-success', 'My flash message'); stated in the Laravel 5 docs doesn't work either.

Edit

Laravel 5.2 Session flash not working even with web middleware duplication. Using ['middlewareGroups' => 'web'] instead of ['middleware' => 'web'] does fix the problem but assuming this is not the way to go.

  • 写回答

2条回答 默认 最新

  • doumenshi1475 2016-04-29 09:24
    关注

    After searching around out of curiosity for this problem i noticed an interesting update for laravel version >= 5.2.27 that applies by default the web middleware group to all the routes defined in routes.php.

    Now this leads me to think that by declaring the middleware ['middleware' => 'web'] will lead to the code getting called twice, thus clearing the non-persistent flash messages.

    A solution based on my assumption would be to simply not use:

    Route::group(['middleware' => 'web'], function () {
    });
    

    This is where i found the update information :) Laravel 5.2 Auth not Working

    评论

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器