I have some legacy urls with get params that I want to redirect to the route without these get parameters.
In my web.php I have:
Route::get('/', ['as' => 'welcome', 'uses' => 'PageController@welcome']);
public function welcome(Request $request)
{
if($request->has('page_id')) {
redirect()->to('welcome', 302);
}
return view('welcome');
}
redirect()->to('welcome', 302)->with('page_id', null);
You should use return
in front of the redirect()
method to make it work:
public function welcome(Request $request)
{
if($request->has('page_id')) {
return redirect()->route('welcome');
}
return view('welcome');
}
Hope this helps!