Reputation: 575
I would like to have a dynamic route like: domain.com/user, where {user} is the user ID (eg. domain.com/12345).
At the same time, I should also be able to set domain.com/about or domain.com/contact, and so on.
Is this possible with Laravel? If yes, can someone please describe how I can accomplish this?
Thanks in advance
Upvotes: 0
Views: 95
Reputation: 16283
Yes it is possible.
Route::get('about', 'YourAboutController@method');
Route::get('contact', 'YourContactController@method');
Route::get('{userid}', 'YourUserController@method');
You could even go as far as to specify what userid
should be, i.e. a number
Route::get('{userid}', 'YourUserController@method')->where('userid', '[0-9]+');
Upvotes: 1
Reputation: 6393
maintain the order:
Route::get('about', function(){});
Route::get('contact', function(){});
Route::get('{user}', function(){});
Route::pattern('user', '[0-9]+');
Upvotes: 1