简体   繁体   English

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

[英]Redirect from controller to named route with data in laravel

I'm gonna try to explain my problem: 我将尝试解释我的问题:

  • I have a named route called 'form.index' where I show a html form. 我有一个名为“ form.index”的命名路由,其中​​显示了一个HTML表单。
  • In FormController I retrieve all form data. 在FormController中,我检索所有表单数据。
  • After do some stuff with these data, I want to redirect to another named route 'form.matches' with some items collection. 在对这些数据进行了一些处理之后,我想使用一些项集合重定向到另一个名为route.form.matches的路径。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM