[英]Redirect from controller to named route with data in laravel
I'm gonna try to explain my problem: 我将尝试解释我的问题:
URLS 网址
form.index -> websiteexample/form
form.index-> websiteexample / form
form.matches -> websiteexample/matches
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'));
}
The problem: 问题:
When the redirects of match function occurs, I get an error "Undefined variable: list' in matches funcion. 发生匹配功能重定向时,在匹配功能中出现错误“未定义变量:列表”。
You can use Redirect::route() to redirect to a named route and pass an array of parameters as the second argument 您可以使用Redirect :: route()重定向到命名路由,并传递参数数组作为第二个参数
Redirect::route('route.name',array('param1' => $param1,'param2' => $param2));
Hope this helps you. 希望这对您有所帮助。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.