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'); + } +};