我有一个具有重定向功能的控制器:
public function myControllerMethod() 
{
    $data = $this->blabla();
    return Redirect::to('previousroute')->with('data', $data);
}前面的路由由otherControllerMethod()处理,如下所示:
public function otherControllerMethod()
{
    $data = Session::get('data');
    return $this->makeView($data);
}不幸的是,Laravel忘记了这个会话数据。我以前已经做过很多次了,我从来没有见过在一次重定向后忘记会话闪存数据的情况。这里发生什么事情?我尝试过添加和删除"web“中间件,但都不起作用。如果有人知道为什么会发生这种情况,请告诉我。
发布于 2016-06-24 13:27:42
use Session;
public function myControllerMethod() 
{
    $data = $this->blabla();
    Session::set('data', $data);
    return Redirect::to('previousroute')->with('data', $data);
}
public function otherControllerMethod()
{
    $data = Session::get('data');
    return $this->makeView($data);
}试着这样做。使用会话并在会话中设置数据,然后从您想要的位置获取数据。
发布于 2016-06-24 05:33:40
我以前也遇到过同样的问题。基本上,在使用Redirect外观进行重定向时,我需要调用send函数。因此,您需要将myControllerMethod更改为:
public function myControllerMethod() 
{
    $data = $this->blabla();
    return Redirect::to('previousroute')->with('data', $data)->send();
}作为send(),类Symfony\Component\HttpFoundation\Response的函数调用函数sendContent(),该函数在重定向时发送数据。
希望这能有所帮助。
发布于 2016-06-24 05:15:40
在myControllerMethod中,您将data obj/var作为请求传递。
在otherControllerMethod中,您正在请求未设置的会话数据。
为了将数据放到会话中,您应该执行以下操作:
Session::put('data','value')然后,它将通过以下方式提供:
Session::get('data');https://stackoverflow.com/questions/38001629
复制相似问题