52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Producto extends Model
|
|
{
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'name', 'price', 'solidario', 'bono', 'categoria_id', 'barrio_id'
|
|
];
|
|
|
|
/**
|
|
* La categoría a la que pertenece el producto.
|
|
*/
|
|
public function categoria(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Categoria::class);
|
|
}
|
|
|
|
/**
|
|
* Los pedidos que tienen al producto.
|
|
*/
|
|
public function pedidos(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(Pedido::class)->withPivot(['cantidad']);
|
|
}
|
|
|
|
/**
|
|
* Las caracteristicas que pertenecen al producto.
|
|
*/
|
|
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);
|
|
}
|
|
}
|