Birmingham mumbai


Download 1.3 Mb.
Pdf ko'rish
bet56/68
Sana05.01.2022
Hajmi1.3 Mb.
#227543
1   ...   52   53   54   55   56   57   58   59   ...   68
Bog'liq
Laravel 5 Essentials

[

 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.


Download 1.3 Mb.

Do'stlaringiz bilan baham:
1   ...   52   53   54   55   56   57   58   59   ...   68




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling