[
27
]
Restricting the route parameters
In the pattern of the second route,
{id}
currently matches any string or number.
To restrict it so that it only matches numbers, we can chain a
where
method to our
route as follows:
Route::get('cats/{id}', function($id) {
sprintf('Cat #%d', $id);
})->where('id', '[0-9]+');
The
where
method takes two arguments: the first one is the name of the parameter
and the second one is the regular expression pattern that it needs to match.
If you now try to visit an invalid URL, nginx (the server software serving the
application) will display a 404 Not Found error page.
Do'stlaringiz bilan baham: |