Did your IDE show any errors in the code.
Redirect to the same route but with different parameter values
Hi,
in the project that I'm working on I've got some pages with this kind of url, two of them are about and news:
localhost/{param1}/about
localhost/{param2}/about
localhost/{param1}/news
localhost/{param2}/news
Every page has its own route with its own controller.
Is it possibile to make a middleware that if the {paramX} has not a certain value (maybe inside of an array) it will redirect to the same original route BUT with the {paramX}} set to a different fixed value?
With that I can use a single generic function that works with all this kind of pages (and their respective routes/controllers).
I saw that it's possible to get Route::getCurrentRoute()->getActionName() but I don't kown how to use it with return redirect()->route or something similar.
Thank you in advance for your support.
[Edit] given a route extracted from a request, is it possible to do something like this inside the middleware?
public function handle(Request $request, Closure $next)
{
$route = $request->route();
if (!in_array($request->param1, ['aaa', 'bbb', 'ccc', true))
{
$route->parameters['param1'] = 'aaa';
return redirect()->$route;
}
return $next($request);
}
Bye
Please or to participate in this conversation.