Redirect::route with parameter in URL in Laravel 5
You can pass the route parameters as second argument to route()
:
return \Redirect::route('regions', [$id])->with('message', 'State saved correctly!!!');
If it's only one you also don't need to write it as array:
return \Redirect::route('regions', $id)->with('message', 'State saved correctly!!!');
In case your route has more parameters, or if it has only one, but you want to clearly specify which parameter has each value (for readability purposes), you can always do this:
return \Redirect::route('regions', ['id'=>$id,'OTHER_PARAM'=>'XXX',...])->with('message', 'State saved correctly!!!');
You could still do it like this:
return redirect()->route('regions', $id)->with('message', 'State saved correctly!!!');
In cases where you have multiple parameters, you can pass the parameters as an array, for example: say you had to pass the capital of a particular region in you route, your route could look something like the following:
Route::get('states/{id}/regions/{capital}', ['as' => 'regions', 'uses' => 'RegionController@index']);
and you can then redirect using:
return redirect()->route('regions', ['id' => $id, 'capital' => $capital])->with('message', 'State saved correctly!');