Redirect::route with parameter in URL in Laravel

1020 0 0 0

Last Updated : 2025-04-29 00:07:31

redirect to specific route with parameters in URl in laravel

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 can pass compact in redirection with parameters like this


 return redirect()->route('main.project', ['id'=>$project->id,'name'=>$project->name])->with( ['project' => $project] ); 

Mahmoud Anwar

Mahmoud Anwar

Back End Developer with a passion for developing innovative web applications that expedite the efficiency and effectiveness of organizational success. Well-versed in technology and writing code to create systems that are reliable and user-friendly. Also has the proven ability to motivate, educate, and collaborate effectively to build web applications and effectively track changes. Confident communicator, strategic thinker, and innovative creator to develop software that is customized to meet a company’s organizational needs, highlight their core competencies, and further their success.