42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Product;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CatalogoController extends Controller
|
|
{
|
|
/**
|
|
* Muestra los registros de ventas con buscador y paginación.
|
|
*/
|
|
public function index(Request $request)
|
|
{
|
|
// Consulta base
|
|
$query = Product::query();
|
|
|
|
// Lógica del Buscador: Si recibimos algo en el input "search"
|
|
if ($request->has('search')) {
|
|
$searchTerm = $request->input('search');
|
|
|
|
$query->where(function($q) use ($searchTerm) {
|
|
$q->where('name', 'like', "%{$searchTerm}%")
|
|
->orWhere('sku', 'like', "%{$searchTerm}%");
|
|
});
|
|
}
|
|
$query->whereIn('type', ['bike', 'accessory', 'clothing', 'spare']);
|
|
$query->where('stock_quantity', '>', 0); // Solo mostrar si tiene stock
|
|
|
|
// Resultados paginados
|
|
$products = $query->paginate(12)->withQueryString(); // withQueryString mantiene la búsqueda al cambiar de página
|
|
|
|
// Devuelve la vista
|
|
return view('catalogo.index', compact('products'));
|
|
}
|
|
|
|
public function show(Product $product)
|
|
{
|
|
return view('catalogo.show', compact('product'));
|
|
}
|
|
}
|