Laravel 5.4 Routes
I currently have multiple routes in Laravel 5, but I want to combine them, not separately, I want them to be grouped, how can I do that?
Route::get('url1', function() {
return Redirect::to('/');
}
Route::get('url2', function() {
return Redirect::to('/');
}
Route::get('url3', function() {
return Redirect::to('/');
}
How can I only make one route so I don't have to repeat it like:
Route::get('url1','url2','url3', function(){
return Redirect::to('/');
});
Thank.
+3
source to share
3 answers
You can use regex for your routes:
Route::get('{url}', function ($name) {
Redirect::to('/');
})->where('url', 'url[0-9]+');
This will redirect all routes numbered per url
If they are different, you can use the same logic:
Route::get('{url}', function ($name) {
Redirect::to('/');
})->where('url', 'url1|url2|url3');
+1
source to share