Answer the question
In order to leave comments, you need to log in
How to build a URL for a given route?
Reading the Lumen documentation https://lumen.laravel.com/docs/5.8/routing.
Reached Optional parameters.
1. Do I understand correctly that in order to create a route that has an optional id parameter (either a number or nothing), that is, both /profile and /profile/7 should be processed in one place, I must write the following code?
$router->get('profile[/{id:[0-9]+}]', ['as' => 'profile', function ($id=null) {
if(!$id){
return "id is empty";
}
return "id:$id";
}]);
route('profile',['id' => 5]) // вернет http://localhost:8000/profile[/5] а хотелось бы http://localhost:8000/profile/5
route('profile') //вернет http://localhost:8000/profile[/{id:[0-9]+}] а хотелось бы http://localhost:8000/profile
Answer the question
In order to leave comments, you need to log in
$router->get('profiles', '[email protected]');
$router->get('profiles/{id}', 'Pro[email protected]');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question