使用laravel中的数据从控制器重定向到命名路由

时间:2019-04-08 11:16:47

标签: laravel

我将尝试解释我的问题:

  • 我有一个名为“ form.index”的命名路由,其中​​显示了html表单。
  • 在FormController中,我检索所有表单数据。
  • 在对这些数据进行了一些处理之后,我想使用一些项集合重定向到另一个名为route.form.matches的路径。

URLS

  

form.index->​​ websiteexample / form

     

form.matches-> websiteexample / matches

FormController

public function match(FormularioRequest $request)
{
    // Some stuffs

    $list = /*Collection*/;

    return redirect()->route('form.matches')->with(compact('list'));
}

public function matches()
{
    // How to retrieve $list var here?
    return view('form.views.matches')->with(compact('list'));
}

问题:

当进行匹配功能的重定向时,在匹配函数中出现错误“未定义变量:列表”。

2 个答案:

答案 0 :(得分:1)

您可以使用Redirect :: route()重定向到指定的路由,并将参数数组作为第二个参数传递

Redirect::route('route.name',array('param1' => $param1,'param2' => $param2));

希望这对您有所帮助。

答案 1 :(得分:1)

 public function match(Request $request)
 {
// Operations

$list = //Data Collection;

return redirect()->route('form.matches')->with('list',$list);
}

In view
@if(Session::has('list'))
<div>  
{!!Session::get('list')!!}
</div>
@endif
相关问题