Named route redirects with query parameters

In a project I'm working on I thought I'd be clever and add an intermediate route of /foo which redirects the user to the appropriate place depending on their settings. This has the benefit of having one clear route which we can use and also separates the logic into another method within the controller.

Our case requires that the route is sent POST parameters, which must be forwarded to the subsequent route too.

If you're sending a parameter to that route, it's just a case of Redirect::route('foo', $fooId), but how do I send through all of the POST parameters too?

Well friends, you do this:

public function foo(Model $model)  
    $foo = ['id' => $model->id]; // Usually we just send $model->id to the route method.
    $params = Input::all();
    $query = array_merge($foo, $params);

    return Redirect::route('foo', $query);

Nice and easy, right!

comments powered by Disqus