From e54cf6a86d28f2bff4b169aa5503ff89ad6e80f6 Mon Sep 17 00:00:00 2001 From: nat Date: Thu, 13 Jan 2022 20:15:46 -0300 Subject: [PATCH] =?UTF-8?q?Se=20muestra=20listado=20de=20productos=20al=20?= =?UTF-8?q?clicar=20en=20cada=20categor=C3=ADa.=20Men=C3=BA=20de=20migas?= =?UTF-8?q?=20(breadcrumbs)=20lleva=20de=20vuelta=20al=20listado=20de=20ca?= =?UTF-8?q?tegor=C3=ADas.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/ProductoController.php | 3 +- app/Http/Resources/ProductoResource.php | 29 + database/seeds/ProductoSeeder.php | 6 +- public/css/app.css | 7 +- public/js/app.js | 29 +- public/js/productos.js | 55 +- resources/csv/productos.csv | 718 +++++++++--------- resources/views/layouts/app.blade.php | 9 +- 8 files changed, 481 insertions(+), 375 deletions(-) create mode 100644 app/Http/Resources/ProductoResource.php diff --git a/app/Http/Controllers/Api/ProductoController.php b/app/Http/Controllers/Api/ProductoController.php index 246c319..e196fa0 100644 --- a/app/Http/Controllers/Api/ProductoController.php +++ b/app/Http/Controllers/Api/ProductoController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Filtros\FiltroDeProducto; +use App\Http\Resources\ProductoResource; use App\Producto; class ProductoController extends Controller @@ -18,7 +19,7 @@ class ProductoController extends Controller */ public function index(FiltroDeProducto $filtros, Request $request) { - return Producto::filtrar($filtros)->paginate(Producto::getPaginar($request)); + return ProductoResource::collection(Producto::filtrar($filtros)->paginate(Producto::getPaginar($request))); } /** diff --git a/app/Http/Resources/ProductoResource.php b/app/Http/Resources/ProductoResource.php new file mode 100644 index 0000000..b0210f3 --- /dev/null +++ b/app/Http/Resources/ProductoResource.php @@ -0,0 +1,29 @@ + $this->id, + 'nombre' => $this->nombre, + 'precio' => $this->precio, + 'categoria' => $this->categoria, + 'proveedor' => optional($this->proveedor)->nombre, + 'imagen' => optional($this->poster)->url(), + 'descripcion' => $this->descripcion, + 'apto_veganxs' => $this->apto_veganxs, + 'apto_caliacxs' => $this->apto_caliacxs + ]; + } +} diff --git a/database/seeds/ProductoSeeder.php b/database/seeds/ProductoSeeder.php index 923d89d..c6e8494 100644 --- a/database/seeds/ProductoSeeder.php +++ b/database/seeds/ProductoSeeder.php @@ -2,6 +2,7 @@ use Illuminate\Database\Seeder; use League\Csv\Reader; +use App\Proveedor; class ProductoSeeder extends Seeder { @@ -23,7 +24,10 @@ class ProductoSeeder extends Seeder $toInsert[] = [ 'categoria' => $registro['categoria'], 'nombre' => $registro['producto'], - 'precio' => $registro['precio'] + 'precio' => $registro['precio'], + 'proveedor_id' => isset($registro['proveedor']) ? Proveedor::firstOrCreate([ + 'nombre' => $registro['proveedor'] + ])->id : null ]; } diff --git a/public/css/app.css b/public/css/app.css index 6ad3b7e..1a9b028 100644 --- a/public/css/app.css +++ b/public/css/app.css @@ -1,3 +1,8 @@ p.navbar-item:empty { display: none; -} \ No newline at end of file +} + +.breadcrumb a { + color: #cc0f35; +} + diff --git a/public/js/app.js b/public/js/app.js index 16e7d43..38d9e2f 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -1,6 +1,8 @@ +window.Event = new Vue(); + Vue.component('nav-bar', { template: ` -