Is there a better way of doing this in Laravel 4 without repeating code?
Route::get('site/{url}', 'SearchController@index');
Route::get('test1/{url}', 'SearchController@index');
Route::get('test2/{url}', 'SearchController@index');
ie pointing multiple urls to single method with query string values. What is the best practice to achieve this?
Thanks in advance for your suggestions.
Make it one route with a dynamic first segment and restrict that to a set of values with regex:
Route::get('{first}/{url}', 'SearchController@index')
->where('first', '(site|test1|test2)');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.