diff --git a/BD/modelo.mwb b/BD/modelo.mwb index 860f16a..0728670 100644 Binary files a/BD/modelo.mwb and b/BD/modelo.mwb differ diff --git a/BD/modelo.mwb.bak b/BD/modelo.mwb.bak new file mode 100644 index 0000000..860f16a Binary files /dev/null and b/BD/modelo.mwb.bak differ diff --git a/BD/tablas.sql b/BD/tablas.sql new file mode 100644 index 0000000..8127864 --- /dev/null +++ b/BD/tablas.sql @@ -0,0 +1,128 @@ +-- MySQL Script generated by MySQL Workbench +-- Tue Sep 1 20:05:16 2026 +-- Model: New Model Version: 1.0 +-- MySQL Workbench Forward Engineering + +SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0; +SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0; +SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'; + +-- ----------------------------------------------------- +-- Schema taller_bd +-- ----------------------------------------------------- + +-- ----------------------------------------------------- +-- Schema taller_bd +-- ----------------------------------------------------- +CREATE SCHEMA IF NOT EXISTS `taller_bd` DEFAULT CHARACTER SET utf8 ; +USE `taller_bd` ; + +-- ----------------------------------------------------- +-- Table `taller_bd`.`categorias` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `taller_bd`.`categorias` ( + `id_categoria` INT NOT NULL AUTO_INCREMENT, + `nombre` VARCHAR(250) NULL, + `descripcion` TEXT NULL, + `created_at` TIMESTAMP NULL, + `deleted_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL, + PRIMARY KEY (`id_categoria`)) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `taller_bd`.`codigo_barras` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `taller_bd`.`codigo_barras` ( + `id_codigo_barras` INT NOT NULL AUTO_INCREMENT, + `codigo` VARCHAR(45) NULL, + `created_at` TIMESTAMP NULL, + `deleted_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL, + PRIMARY KEY (`id_codigo_barras`)) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `taller_bd`.`productos` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `taller_bd`.`productos` ( + `id_producto` INT NOT NULL AUTO_INCREMENT, + `nombre` VARCHAR(250) NULL, + `descripcion` TEXT NULL, + `precio` DECIMAL(10,2) NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL, + `deleted_at` TIMESTAMP NULL, + `codigo_barras_id` INT NOT NULL, + `categoria_id` INT NOT NULL, + INDEX `fk_productos_codigo_barras_idx` (`codigo_barras_id` ASC) VISIBLE, + PRIMARY KEY (`id_producto`), + INDEX `fk_productos_categorias1_idx` (`categoria_id` ASC) VISIBLE, + CONSTRAINT `fk_productos_codigo_barras` + FOREIGN KEY (`codigo_barras_id`) + REFERENCES `taller_bd`.`codigo_barras` (`id_codigo_barras`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `fk_productos_categorias1` + FOREIGN KEY (`categoria_id`) + REFERENCES `taller_bd`.`categorias` (`id_categoria`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `taller_bd`.`etiquetas` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `taller_bd`.`etiquetas` ( + `id_etiqueta` INT NOT NULL AUTO_INCREMENT, + `nombre` VARCHAR(250) NULL, + `created_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL, + `deleted_at` TIMESTAMP NULL, + PRIMARY KEY (`id_etiqueta`)) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `taller_bd`.`persona` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `taller_bd`.`persona` ( + `id_persona` INT NOT NULL AUTO_INCREMENT, + `nombre` VARCHAR(250) NULL, + `apellido` VARCHAR(250) NULL, + `created_at` TIMESTAMP NULL, + `deleted_at` TIMESTAMP NULL, + `updated_at` TIMESTAMP NULL, + `personacol` VARCHAR(45) NULL, + PRIMARY KEY (`id_persona`)) +ENGINE = InnoDB; + + +-- ----------------------------------------------------- +-- Table `taller_bd`.`productos_has_etiquetas` +-- ----------------------------------------------------- +CREATE TABLE IF NOT EXISTS `taller_bd`.`productos_has_etiquetas` ( + `producto_id` INT NOT NULL, + `etiqueta_id` INT NOT NULL, + PRIMARY KEY (`producto_id`, `etiqueta_id`), + INDEX `fk_productos_has_etiquetas_etiquetas1_idx` (`etiqueta_id` ASC) VISIBLE, + INDEX `fk_productos_has_etiquetas_productos1_idx` (`producto_id` ASC) VISIBLE, + CONSTRAINT `fk_productos_has_etiquetas_productos1` + FOREIGN KEY (`producto_id`) + REFERENCES `taller_bd`.`productos` (`id_producto`) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT `fk_productos_has_etiquetas_etiquetas1` + FOREIGN KEY (`etiqueta_id`) + REFERENCES `taller_bd`.`etiquetas` (`id_etiqueta`) + ON DELETE NO ACTION + ON UPDATE NO ACTION) +ENGINE = InnoDB; + + +SET SQL_MODE=@OLD_SQL_MODE; +SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS; +SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; diff --git a/app/Http/Controllers/CategoriasController.php b/app/Http/Controllers/CategoriasController.php index e132a98..cfca509 100644 --- a/app/Http/Controllers/CategoriasController.php +++ b/app/Http/Controllers/CategoriasController.php @@ -28,7 +28,7 @@ class CategoriasController extends Controller return view('categorias.index', ["categorias"=>$categorias]); } public function show($id){ - $categoria = Categorias::findOrfail($id); + $categoria = Categorias::with('productos')->findOrfail($id); $categoria->formatear_texto(); return view('categorias.show', ["cat"=>$categoria]); } diff --git a/app/Http/Controllers/ProductoController.php b/app/Http/Controllers/ProductoController.php index 39a1900..f9efb5a 100644 --- a/app/Http/Controllers/ProductoController.php +++ b/app/Http/Controllers/ProductoController.php @@ -3,8 +3,11 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; - +use App\Models\Producto; class ProductoController extends Controller { - // + public function index(Request $request){ + $productos = Producto::with('categorias','codigo_barras')->get(); + return view('productos.index', ["productos"=>$productos]); + } } diff --git a/app/Models/Categorias.php b/app/Models/Categorias.php index 3645b36..98db9ff 100644 --- a/app/Models/Categorias.php +++ b/app/Models/Categorias.php @@ -22,5 +22,8 @@ class Categorias extends Model 'descripcion', ]; +public function productos() { +return $this->hasMany(Producto::class,'categoria_id','id_categoria'); +} } diff --git a/app/Models/Producto.php b/app/Models/Producto.php index 2df2e0d..37cde79 100644 --- a/app/Models/Producto.php +++ b/app/Models/Producto.php @@ -19,8 +19,17 @@ class Producto extends Model 'nombre', 'descripcion', 'categoria_id', - 'codigo_barras_id' + 'codigo_barras_id', + 'precio', ]; + public function categorias() { + return $this->belongsTo(Categorias::class, 'categoria_id', 'id_categoria'); + } + + public function codigo_barras(){ + + return $this->belongsTo(CodigoBarras::class,'codigo_barras_id','id_codigo_barras'); + } } diff --git a/resources/views/productos/index.blade.php b/resources/views/productos/index.blade.php new file mode 100644 index 0000000..22664ed --- /dev/null +++ b/resources/views/productos/index.blade.php @@ -0,0 +1,120 @@ +@extends('layouts.admin') +@section('contenido') + + + +
| Id | +Nombre | +Descripcion | +Precio | +Codigo_barra | +Categoria | +Acciones | +
|---|---|---|---|---|---|---|
| {{ $prod->id_producto }} | +{{ $prod->nombre }} | +{{ $prod->descripcion }} | +{{ $prod->precio }} | +{{ $prod->codigo_barras->codigo }} | +{{ $prod->categorias->nombre}} | ++ + + + | +