Created
June 24, 2020 07:53
-
-
Save parzibyte/d9830103571978003c740a8b36e44c92 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Función llamada desde el controlador; es un ejemplo, tú puedes colocar el código donde gustes | |
public function index(Request $request) | |
{ | |
$busqueda = ""; | |
if ($request->get("busqueda")) { | |
$busqueda = $request->get("busqueda"); | |
} | |
# Exista o no exista búsqueda, los ordenamos | |
$builder = Producto::orderBy("descripcion"); | |
if ($busqueda) { | |
# Si hay búsqueda, agregamos el filtro | |
$builder->where("descripcion", "LIKE", "%$busqueda%"); | |
} | |
# Al final de todo, invocamos a paginate que tendrá todos los filtros | |
$productos = $builder->paginate(5); | |
return view("productos.productos_index", [ | |
"productos" => $productos, | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment