In Laravel, you can define a route parameter by enclosing a word in curly braces {}
within the route declaration.
Here's an example of how to define a route parameter in Laravel:
Route::get('users/{id}', function ($id) {
// Your logic here
});
In the above example, {id}
is the route parameter. When a user visits a URL like users/1
, Laravel will capture the value 1
as the $id
parameter. You can then use the parameter in your callback function to perform any specific actions or retrieve data based on the value.
You can also define multiple route parameters in a single route by separating them with slashes:
Route::get('users/{id}/posts/{post_id}', function ($id, $postId) {
// Your logic here
});
In this case, id
and post_id
are two separate route parameters, and you can access their respective values in the callback function.
Note: The parameter names inside the route declaration must match the parameter names passed to the callback function.