feature/modelos-y-migraciones #3

Merged
rho merged 28 commits from feature/modelos-y-migraciones into master 2024-03-14 16:34:44 -03:00
2 changed files with 39 additions and 0 deletions
Showing only changes of commit 1129a9e11b - Show all commits

View file

@ -24,4 +24,11 @@ class Pedido extends Model
return $this->belongsTo(Barrio::class); return $this->belongsTo(Barrio::class);
} }
/**
* Los productos que pertenecen al pedido.
*/
public function productos(): BelongsToMany
{
return $this->belongsToMany(Producto::class);
}
} }

View file

@ -0,0 +1,32 @@
<?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_pedidos', function (Blueprint $table) {
$table->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');
}
};