Reputation: 1754
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');
i.e. pointing multiple urls to single method with query string values. What is the best practice to achieve this?
Thanks in advance for your suggestions.
Upvotes: 2
Views: 862
Reputation: 152860
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)');
Upvotes: 4