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 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数