Agregada relacion 1 - n nulleable entre barrio y producto

This commit is contained in:
Alejandro Tasistro 2024-03-14 23:04:54 -03:00
parent c746e41060
commit 206d06b8bc
3 changed files with 19 additions and 1 deletions

View File

@ -31,4 +31,12 @@ public function pedidos(): HasMany
{
return $this->hasMany(Pedido::class);
}
/**
* Los productos que pertenecen al barrio.
*/
public function productos(): HasMany
{
return $this->hasMany(Producto::class);
}
}

View File

@ -13,7 +13,7 @@ class Producto extends Model
* @var array<int, string>
*/
protected $fillable = [
'name', 'price', 'solidario', 'bono', 'categoria_id'
'name', 'price', 'solidario', 'bono', 'categoria_id', 'barrio_id'
];
/**
@ -39,4 +39,12 @@ public function caracteristicas(): BelongsToMany
{
return $this->belongsToMany(Caracteristica::class);
}
/**
* El barrio a la que pertenece el producto.
*/
public function barrio(): BelongsTo
{
return $this->belongsTo(Barrio::class);
}
}

View File

@ -18,8 +18,10 @@ public function up(): void
$table->unsignedBigInteger('categoria_id');
$table->boolean('solidario');
$table->boolean('bono');
$table->unsignedBigInteger('barrio_id')->nullable();
$table->timestamps();
$table->foreign('categoria_id')->references('id')->on('categorias');
$table->foreign('barrio_id')->references('id')->on('barrios');
});
}