I have a basic route that looks like this:
Route::prefix('/group')->group(function () {
// Some routes here
Route::prefix('/{uuid}')->group(function () {
// Some routes here
Route::get('/user/{id}', 'Controller@preview')->name('view-user')->where('id', '[0-9]+');
}
}
The logic is that I want the id
to be only numerical value. What I want to do now is, to declare a redirection to this, if the value is non-numerical. Let's say the input of id
is fs
. In that case I would want it to redirect to id
with value 1
.
I tried using Route:redirect
, but could not make it work. It looks something like this:
Route::redirect('/group/{uuid}/user/{id}', '/group/{uuid}/user/1')->where('id', '[^0-9]+');
I would prefer to put the redirect inside the groups, but it can be outside if this is the only way. Any help will be greatly appreciated.
What happens is, that I get a 404 error if I have the route redirect declared.
EDIT: I want to do it in the routes/web.php
file. I know how to do it in the controller, but it is not what I need in the current case.
Closures are not an option either, because that would prevent routes caching.