From 2b7a5e1d91d7b826b713102fc8a94a9fe534cb1c Mon Sep 17 00:00:00 2001 From: ale Date: Tue, 12 Mar 2024 17:18:00 -0300 Subject: [PATCH] =?UTF-8?q?relaci=C3=B3n=20manyToMany=20producto=20-=20cat?= =?UTF-8?q?egor=C3=ADa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Models/Producto.php | 8 +++++ ...create_productos_caracteristicas_table.php | 31 +++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 database/migrations/2024_03_12_201211_create_productos_caracteristicas_table.php diff --git a/app/Models/Producto.php b/app/Models/Producto.php index 8695a73..04f935e 100644 --- a/app/Models/Producto.php +++ b/app/Models/Producto.php @@ -22,4 +22,12 @@ public function pedidos(): BelongsToMany { return $this->belongsToMany(Pedido::class); } + + /** + * Las caracteristicas que pertenecen al producto. + */ + public function caracteristicas(): BelongsToMany + { + return $this->belongsToMany(Caracteristica::class); + } } diff --git a/database/migrations/2024_03_12_201211_create_productos_caracteristicas_table.php b/database/migrations/2024_03_12_201211_create_productos_caracteristicas_table.php new file mode 100644 index 0000000..4e6a45e --- /dev/null +++ b/database/migrations/2024_03_12_201211_create_productos_caracteristicas_table.php @@ -0,0 +1,31 @@ +id(); + $table->unsignedBigInteger('producto_id'); + $table->unsignedBigInteger('caracteristica_id'); + $table->timestamps(); + $table->foreign('producto_id')->references('id')->on('productos'); + $table->foreign('caracteristica_id')->references('id')->on('caracteristicas'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('productos_caracteristicas'); + } +};