65 lines
1.4 KiB
PHP
65 lines
1.4 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 = [
|
|
'nombre', 'precio', 'solidario', 'bono', 'barrial', '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);
|
|
}
|
|
|
|
/**
|
|
* Los productos centrales.
|
|
*/
|
|
public static function centrales() {
|
|
return Producto::where([
|
|
'barrial' => false,
|
|
]);
|
|
}
|
|
|
|
function pagaTransporte() : bool {
|
|
return !$this->bono && !$this->barrial;
|
|
}
|
|
}
|