Reputation: 109
i am little bit confused in routing of laravel-5.2 . I am facing one issue. I have two routes that are follows:-
Route::get('{businessname}',BusinessController@getBusiness) //first Route
Route::get('{username}','UsersController@getusername') //second route
So yo see that {businessname}
and {username}
is dynamic.
But when i try to access the url like:-
Localhost:8000/dummy-business-name // this route is going to this function that is right .... -> BusinessController@getBusiness
But when i try second route of username it is also going to getBusiness function
Localhost:8000/kanu-mahajan i want this function should be redirect to UsersController@getusername
I know the alternative of this thing we can define Route like that
Route::get('user/{username}','UsersController@getusername')
But i don't want to do it in this way. Please help me how to do above routing in laravel 5.2 .
Upvotes: 1
Views: 76
Reputation: 3186
You can't do that because it is basically the same route, just a different parameter.
You can do what you suggested with user/{username}
or you can send all parameters to the same function and handle it from there.
For example:
Route::get('{name}', function ($name) {
// if name is username then do something
// or if name is business then do something else
});
Upvotes: 1