From 12634329bc637fce4434b410064a580dbed4746d Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 11 Mar 2024 19:41:52 -0300 Subject: [PATCH 1/3] definiciones y migraciones de pedido --- app/Models/Barrio.php | 8 +++++ app/Models/Pedido.php | 27 +++++++++++++++++ ...2024_03_11_221942_create_pedidos_table.php | 30 +++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 app/Models/Pedido.php create mode 100644 database/migrations/2024_03_11_221942_create_pedidos_table.php diff --git a/app/Models/Barrio.php b/app/Models/Barrio.php index 02384cc..9c48da6 100644 --- a/app/Models/Barrio.php +++ b/app/Models/Barrio.php @@ -23,4 +23,12 @@ public function region(): BelongsTo { return $this->belongsTo(Region::class); } + + /** + * Los pedidos que pertenecen al barrio. + */ + public function pedidos(): HasMany + { + return $this->hasMany(Pedido::class); + } } diff --git a/app/Models/Pedido.php b/app/Models/Pedido.php new file mode 100644 index 0000000..957f298 --- /dev/null +++ b/app/Models/Pedido.php @@ -0,0 +1,27 @@ + + */ + protected $fillable = [ + 'name', + ]; + + /** + * El barrio al que pertenece el pedido. + */ + public function barrio(): BelongsTo + { + return $this->belongsTo(Barrio::class); + } + +} diff --git a/database/migrations/2024_03_11_221942_create_pedidos_table.php b/database/migrations/2024_03_11_221942_create_pedidos_table.php new file mode 100644 index 0000000..2848a1b --- /dev/null +++ b/database/migrations/2024_03_11_221942_create_pedidos_table.php @@ -0,0 +1,30 @@ +id(); + $table->string('name', 100); + $table->unsignedBigInteger('barrio_id'); + $table->foreign('barrio_id')->references('id')->on('barrios'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('pedidos'); + } +}; From 983b63897de449c87d0a2b6b25904580d67c4253 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 11 Mar 2024 19:54:52 -0300 Subject: [PATCH 2/3] definicion y migracion de producto sin nada --- app/Models/Producto.php | 17 ++++++++++++ ...24_03_11_224041_create_productos_table.php | 27 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 app/Models/Producto.php create mode 100644 database/migrations/2024_03_11_224041_create_productos_table.php diff --git a/app/Models/Producto.php b/app/Models/Producto.php new file mode 100644 index 0000000..ee30aac --- /dev/null +++ b/app/Models/Producto.php @@ -0,0 +1,17 @@ +belongsToMany(Pedido::class); + } +} diff --git a/database/migrations/2024_03_11_224041_create_productos_table.php b/database/migrations/2024_03_11_224041_create_productos_table.php new file mode 100644 index 0000000..e524043 --- /dev/null +++ b/database/migrations/2024_03_11_224041_create_productos_table.php @@ -0,0 +1,27 @@ +id(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('productos'); + } +}; From 1129a9e11bf2c05d2198ddc8e0d2a965001425e1 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 11 Mar 2024 19:55:35 -0300 Subject: [PATCH 3/3] definicion de pedido y migracion de productos_pedidos --- app/Models/Pedido.php | 7 ++++ ..._224437_create_productos_pedidos_table.php | 32 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 database/migrations/2024_03_11_224437_create_productos_pedidos_table.php diff --git a/app/Models/Pedido.php b/app/Models/Pedido.php index 957f298..31bd7be 100644 --- a/app/Models/Pedido.php +++ b/app/Models/Pedido.php @@ -24,4 +24,11 @@ public function barrio(): BelongsTo return $this->belongsTo(Barrio::class); } + /** + * Los productos que pertenecen al pedido. + */ + public function productos(): BelongsToMany + { + return $this->belongsToMany(Producto::class); + } } diff --git a/database/migrations/2024_03_11_224437_create_productos_pedidos_table.php b/database/migrations/2024_03_11_224437_create_productos_pedidos_table.php new file mode 100644 index 0000000..e61e66b --- /dev/null +++ b/database/migrations/2024_03_11_224437_create_productos_pedidos_table.php @@ -0,0 +1,32 @@ +id(); + $table->unsignedBigInteger('pedido_id'); + $table->unsignedBigInteger('producto_id'); + $table->unsignedInteger('ammount'); + $table->timestamps(); + $table->foreign('pedido_id')->references('id')->on('pedidos'); + $table->foreign('producto_id')->references('id')->on('productos'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('productos_pedidos'); + } +};