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-03-19 22:13:49 -03:00
|
|
|
'name', 'price', '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-03-19 22:13:49 -03:00
|
|
|
|
2024-03-31 18:22:03 -03:00
|
|
|
/**
|
|
|
|
* Los productos centrales.
|
|
|
|
*/
|
|
|
|
public static function centrales() {
|
|
|
|
return Producto::where([
|
|
|
|
'barrial' => false,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2024-03-19 22:13:49 -03:00
|
|
|
function pagaTransporte() : bool {
|
|
|
|
return !$this->bono && !$this->barrial;
|
|
|
|
}
|
2024-03-11 19:54:52 -03:00
|
|
|
}
|