listado de productos
This commit is contained in:
parent
28b82b9789
commit
0b8cd08fa9
BIN
BD/modelo.mwb
BIN
BD/modelo.mwb
Binary file not shown.
BIN
BD/modelo.mwb.bak
Normal file
BIN
BD/modelo.mwb.bak
Normal file
Binary file not shown.
128
BD/tablas.sql
Normal file
128
BD/tablas.sql
Normal file
|
|
@ -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;
|
||||||
|
|
@ -28,7 +28,7 @@ class CategoriasController extends Controller
|
||||||
return view('categorias.index', ["categorias"=>$categorias]);
|
return view('categorias.index', ["categorias"=>$categorias]);
|
||||||
}
|
}
|
||||||
public function show($id){
|
public function show($id){
|
||||||
$categoria = Categorias::findOrfail($id);
|
$categoria = Categorias::with('productos')->findOrfail($id);
|
||||||
$categoria->formatear_texto();
|
$categoria->formatear_texto();
|
||||||
return view('categorias.show', ["cat"=>$categoria]);
|
return view('categorias.show', ["cat"=>$categoria]);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,11 @@
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use App\Models\Producto;
|
||||||
class ProductoController extends Controller
|
class ProductoController extends Controller
|
||||||
{
|
{
|
||||||
//
|
public function index(Request $request){
|
||||||
|
$productos = Producto::with('categorias','codigo_barras')->get();
|
||||||
|
return view('productos.index', ["productos"=>$productos]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,5 +22,8 @@ class Categorias extends Model
|
||||||
'descripcion',
|
'descripcion',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function productos() {
|
||||||
|
|
||||||
|
return $this->hasMany(Producto::class,'categoria_id','id_categoria');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,17 @@ class Producto extends Model
|
||||||
'nombre',
|
'nombre',
|
||||||
'descripcion',
|
'descripcion',
|
||||||
'categoria_id',
|
'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');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
120
resources/views/productos/index.blade.php
Normal file
120
resources/views/productos/index.blade.php
Normal file
|
|
@ -0,0 +1,120 @@
|
||||||
|
@extends('layouts.admin')
|
||||||
|
@section('contenido')
|
||||||
|
|
||||||
|
<!-- row => fila del sistema de grillas Bootstrap
|
||||||
|
justify-content-center => centra horizontalmente los contenidos
|
||||||
|
align-items-center => centra verticalmente
|
||||||
|
no centran el texto, centran las columnas dentro de la fila
|
||||||
|
-->
|
||||||
|
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<!-- col-12 => ocupa todo el ancho en pantallas pequeñas
|
||||||
|
col-md-11 => ocupa 11/12 del ancho en pantallas medianas o mayores -->
|
||||||
|
<div class="col-12 col-md-11">
|
||||||
|
<h3>Listado de Productos</h3>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<div class="col-md-2">
|
||||||
|
<!-- btn => estilo de botón Bootstrap
|
||||||
|
btn-success => verde (acción positiva)
|
||||||
|
btn-block => ocupa todo el ancho de la columna
|
||||||
|
btn-lg => tamaño grande -->
|
||||||
|
<a href="{{ route('categorias.create') }}"
|
||||||
|
class="btn btn-success btn-block btn-lg"
|
||||||
|
title="Nueva Categoria">
|
||||||
|
Nuevo
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<div class="row justify-content-center align-items-center">
|
||||||
|
<div class="col-12 col-md-11">
|
||||||
|
|
||||||
|
<!-- Includes de Blade para mensajes de éxito y errores -->
|
||||||
|
@include('compartido.mensajes')
|
||||||
|
@include('compartido.errores')
|
||||||
|
|
||||||
|
<!-- table-responsive => hace que la tabla sea "scrollable" en pantallas pequeñas -->
|
||||||
|
<div class="table-responsive">
|
||||||
|
|
||||||
|
<!-- table => tabla con estilos básicos
|
||||||
|
table-striped => filas alternadas con fondo gris
|
||||||
|
table-bordered => agrega bordes a todas las celdas
|
||||||
|
table-hover => resalta la fila al pasar el mouse -->
|
||||||
|
<table class="table table-striped table-bordered table-hover" id="example">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Id</th>
|
||||||
|
<th>Nombre</th>
|
||||||
|
<th>Descripcion</th>
|
||||||
|
<th>Precio</th>
|
||||||
|
<th>Codigo_barra</th>
|
||||||
|
<th>Categoria</th>
|
||||||
|
<th>Acciones</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach($productos as $prod)
|
||||||
|
<tr>
|
||||||
|
<td>{{ $prod->id_producto }}</td>
|
||||||
|
<td>{{ $prod->nombre }}</td>
|
||||||
|
<td>{{ $prod->descripcion }}</td>
|
||||||
|
<td>{{ $prod->precio }}</td>
|
||||||
|
<td>{{ $prod->codigo_barras->codigo }}</td>
|
||||||
|
<td>{{ $prod->categorias->nombre}}</td>
|
||||||
|
<td align="center">
|
||||||
|
|
||||||
|
<form method="POST" action="{{ route('productos.destroy', $prod->id_producto) }}" style="display:inline;">
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
|
||||||
|
<!-- btn-info => azul claro (información) -->
|
||||||
|
<a class="btn btn-info"
|
||||||
|
href="{{ route('productos.show', $prod->id_producto) }}"
|
||||||
|
title="Ver más">
|
||||||
|
<i class="fa fa-eye"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- btn-warning => amarillo (advertencia / editar) -->
|
||||||
|
<a class="btn btn-warning"
|
||||||
|
href="{{ route('productos.edit', $prod->id_producto) }}"
|
||||||
|
title="Editar">
|
||||||
|
<i class="fa fa-pencil"></i>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
<!-- btn-danger => rojo (acción destructiva como eliminar) -->
|
||||||
|
<button class="btn btn-danger"
|
||||||
|
onclick="return confirm('¿Está seguro de eliminar la categoría?');"
|
||||||
|
title="Eliminar">
|
||||||
|
<i class="fa fa-remove"></i>
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
@endforeach
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@endsection
|
||||||
|
@push('styles')
|
||||||
|
|
||||||
|
@endpush
|
||||||
|
@push('scripts')
|
||||||
|
<script>
|
||||||
|
// DataTables (plugin JS para mejorar tablas: búsqueda, paginación, exportación)
|
||||||
|
$('#example').DataTable({
|
||||||
|
dom: 'Bfrtip',
|
||||||
|
buttons: ['excel'],
|
||||||
|
pageLength: 5,
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
@endpush
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\CategoriasController;
|
use App\Http\Controllers\CategoriasController;
|
||||||
|
use App\Http\Controllers\ProductoController;
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
| Web Routes
|
| Web Routes
|
||||||
|
|
@ -28,6 +29,7 @@ Route::put('categorias/{categoria}', [CategoriasController::class, 'update'])->n
|
||||||
|
|
||||||
|
|
||||||
Route::resource('categorias', CategoriasController::class)->middleware('auth');
|
Route::resource('categorias', CategoriasController::class)->middleware('auth');
|
||||||
|
Route::resource('productos', ProductoController::class);
|
||||||
Route::put('categorias/restaurar/{categoria}', [CategoriasController::class, 'restaurar'])->name('categorias.restaurar')->middleware('auth');
|
Route::put('categorias/restaurar/{categoria}', [CategoriasController::class, 'restaurar'])->name('categorias.restaurar')->middleware('auth');
|
||||||
Auth::routes();
|
Auth::routes();
|
||||||
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
|
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user