From 1129a9e11bf2c05d2198ddc8e0d2a965001425e1 Mon Sep 17 00:00:00 2001 From: ale Date: Mon, 11 Mar 2024 19:55:35 -0300 Subject: [PATCH] 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'); + } +};