Agregada relacion 1 - n nulleable entre barrio y producto
This commit is contained in:
parent
c746e41060
commit
206d06b8bc
3 changed files with 19 additions and 1 deletions
|
@ -31,4 +31,12 @@ class Barrio extends Model
|
||||||
{
|
{
|
||||||
return $this->hasMany(Pedido::class);
|
return $this->hasMany(Pedido::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Los productos que pertenecen al barrio.
|
||||||
|
*/
|
||||||
|
public function productos(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(Producto::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ class Producto extends Model
|
||||||
* @var array<int, string>
|
* @var array<int, string>
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name', 'price', 'solidario', 'bono', 'categoria_id'
|
'name', 'price', 'solidario', 'bono', 'categoria_id', 'barrio_id'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -39,4 +39,12 @@ class Producto extends Model
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Caracteristica::class);
|
return $this->belongsToMany(Caracteristica::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* El barrio a la que pertenece el producto.
|
||||||
|
*/
|
||||||
|
public function barrio(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Barrio::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,10 @@ return new class extends Migration
|
||||||
$table->unsignedBigInteger('categoria_id');
|
$table->unsignedBigInteger('categoria_id');
|
||||||
$table->boolean('solidario');
|
$table->boolean('solidario');
|
||||||
$table->boolean('bono');
|
$table->boolean('bono');
|
||||||
|
$table->unsignedBigInteger('barrio_id')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
$table->foreign('categoria_id')->references('id')->on('categorias');
|
$table->foreign('categoria_id')->references('id')->on('categorias');
|
||||||
|
$table->foreign('barrio_id')->references('id')->on('barrios');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue