relación manyToMany producto - categoría

This commit is contained in:
Alejandro Tasistro 2024-03-12 17:18:00 -03:00
parent 99431bc64f
commit 2b7a5e1d91
2 changed files with 39 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('productos_caracteristicas', function (Blueprint $table) {
$table->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');
}
};