Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active February 13, 2019 18:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/b3b496e945c58507b10fcddd003a77b5 to your computer and use it in GitHub Desktop.
Save parzibyte/b3b496e945c58507b10fcddd003a77b5 to your computer and use it in GitHub Desktop.
<?php
Route::get("/usuario/{id}", function($id){
return "Solamente respondo si el id tiene 1 o más dígitos numéricos";
})->where("id", '[0-9]+');
#Nota: el slug es el enlace amigable, por ejemplo: crud-de-mysql. Una ruta
# se vería así: articulo/2019/crud-de-mysql
Route::get("/articulo/{anio}/{slug}", function($anio, $slug){
return "Quieres ver un artículo del año $anio con el slug $slug";
})->where(
# Pasar un arreglo con las expresiones que deben cumplir
[
"anio" => '[0-9]{4}', # Año de 4 dígitos exactos (no funcionará después del año 9999)
"slug" => '[A-Za-z0-9-_]+', # Conformado por letras mayúsculas o minúsculas, guiones bajos _ o normales - y números
]
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment