From 441007e66bf55adde30c387db3095c156b8e2cd8 Mon Sep 17 00:00:00 2001 From: ale Date: Thu, 19 Jun 2025 21:29:48 -0300 Subject: [PATCH] Agregado modelo, tabla, y columna en subpedidos para tipo pedido --- app/Subpedido.php | 7 +++- app/TipoPedido.php | 10 +++++ ...06_20_001436_create_tipo_pedidos_table.php | 42 +++++++++++++++++++ 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 app/TipoPedido.php create mode 100644 database/migrations/2025_06_20_001436_create_tipo_pedidos_table.php diff --git a/app/Subpedido.php b/app/Subpedido.php index 26e38e4..6faad84 100644 --- a/app/Subpedido.php +++ b/app/Subpedido.php @@ -12,7 +12,7 @@ use App\Filtros\FiltroDeSubpedido; class Subpedido extends Model { - protected $fillable = ['grupo_de_compra_id', 'aprobado', 'nombre', 'devoluciones_total', 'devoluciones_notas']; + protected $fillable = ['grupo_de_compra_id', 'aprobado', 'nombre', 'devoluciones_total', 'devoluciones_notas', 'tipo_pedido_id']; public function productos(): BelongsToMany { @@ -24,6 +24,11 @@ class Subpedido extends Model return $this->belongsTo(GrupoDeCompra::class); } + public function tipoPedido(): BelongsTo + { + return $this->belongsTo(TipoPedido::class); + } + // Permite que se apliquen los filtros al hacer una request (por ejemplo, de búsqueda) public function scopeFiltrar($query, FiltroDeSubpedido $filtros): Builder { diff --git a/app/TipoPedido.php b/app/TipoPedido.php new file mode 100644 index 0000000..310761a --- /dev/null +++ b/app/TipoPedido.php @@ -0,0 +1,10 @@ +id(); + $table->string("nombre"); + $table->timestamps(); + }); + + $hogar = TipoPedido::firstOrCreate(['nombre' => 'hogar']); + + Schema::table('subpedidos', function (Blueprint $table) use ($hogar) { + $table->foreignId('tipo_pedido_id')->default($hogar->id); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('tipo_pedidos'); + Schema::table('subpedidos', function (Blueprint $table) { + $table->dropColumn('tipo_pedido_id'); + }); + } +}