2024-03-11 19:54:52 -03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2024-03-19 15:40:27 -03:00
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
2024-03-11 19:54:52 -03:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
class Producto extends Model
|
|
|
|
{
|
2024-03-12 17:52:52 -03:00
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
|
|
|
* @var array<int, string>
|
|
|
|
*/
|
|
|
|
protected $fillable = [
|
2024-07-03 19:35:27 -03:00
|
|
|
'nombre', 'precio', 'solidario', 'bono', 'barrial', 'categoria_id', 'barrio_id'
|
2024-03-12 17:52:52 -03:00
|
|
|
];
|
|
|
|
|
2024-03-12 17:05:15 -03:00
|
|
|
/**
|
|
|
|
* La categoría a la que pertenece el producto.
|
|
|
|
*/
|
|
|
|
public function categoria(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Categoria::class);
|
|
|
|
}
|
|
|
|
|
2024-03-11 19:54:52 -03:00
|
|
|
/**
|
|
|
|
* Los pedidos que tienen al producto.
|
|
|
|
*/
|
|
|
|
public function pedidos(): BelongsToMany
|
|
|
|
{
|
2024-03-19 15:40:27 -03:00
|
|
|
return $this->belongsToMany(Pedido::class)->withPivot(['cantidad']);
|
2024-03-11 19:54:52 -03:00
|
|
|
}
|
2024-03-12 17:18:00 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Las caracteristicas que pertenecen al producto.
|
|
|
|
*/
|
|
|
|
public function caracteristicas(): BelongsToMany
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Caracteristica::class);
|
|
|
|
}
|
2024-03-14 23:04:54 -03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* El barrio a la que pertenece el producto.
|
|
|
|
*/
|
|
|
|
public function barrio(): BelongsTo
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Barrio::class);
|
|
|
|
}
|
2024-07-11 21:36:43 -03:00
|
|
|
|
|
|
|
public function pagaTransporte() : bool
|
|
|
|
{
|
|
|
|
return !$this->bono && !$this->barrial;
|
|
|
|
}
|
2024-03-11 19:54:52 -03:00
|
|
|
}
|