douzi5214 2016-01-25 20:01
浏览 27
已采纳

Laravel 5.2。* redirect-> back->没有工作

I want to write some data to my database, if the query fails I want to display an error. I tried the following:

return redirect()->back()->with('data', ['Database Error!']);

The redirect works great, but I cant read out the response in $data

My Blade:

@if (session()->has('data'))
<div class="alert alert-danger" role="alert">...</div>
@endif

//Second try
<?php if(session('data')) echo $message; ?>

But both methods doesn't work, i read a lot of L5.2 Docs but nothing works.

Do i need to modify the session config?!? Or what is the problem?

  • 写回答

2条回答 默认 最新

  • doudinghan8319 2016-01-25 20:33
    关注

    This is a breaking problem with the 5.2 upgrade. What's happening is the middleware which is responsible for display the Session message in all your views is not being utilized because it was moved from the global middleware to the web middleware group.

    There are two ways to fix this:

    1. In your kernel.php file(app/Http/Kernel.php), you can move the middleware \Illuminate\View\Middleware\ShareErrorsFromSession::class back to the protected $middleware property.
    2. Wrap all your web routes with a route group and apply the web middleware to them:

      Route::group(['middleware' => 'web'], function() {
          // Place all your web routes here...(Cut all `Route` which are define in `Route file`, paste here) 
      });
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?