Files
2021-07-20 15:27:55 -04:00

42 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use App\Traits\UuidPrimaryKey;
use App\Exceptions\ModelNotFoundException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Producto extends Model {
use UuidPrimaryKey, SoftDeletes;
protected $table = 'productos';
protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot'];
protected $fillable = [
'id', 'nombre', 'precio_venta', 'categoria_id',
'zona_produccion_id', 'restaurante_id'
];
public static function findOrFail($id) {
$producto = Producto::find($id);
if(!$producto) throw new ModelNotFoundException("producto", $id);
return $producto;
}
public function recetas() {
return $this->hasMany(Receta::class, 'producto_id');
}
public function categoria() {
return $this->belongsTo(Categoria::class);
}
public function zonaProduccion() {
return $this->belongsTo(ZonaProduccion::class);
}
public function restaurante() {
return $this->belongsTo(Restaurante::class);
}
}