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

31 lines
860 B
PHP

<?php
namespace App\Models;
use App\Traits\UuidPrimaryKey;
use App\Exceptions\ModelNotFoundException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Ingrediente extends Model {
use UuidPrimaryKey, SoftDeletes;
protected $table = 'ingredientes';
protected $hidden = ['created_at', 'updated_at', 'deleted_at', 'pivot'];
protected $fillable = ['id', 'nombre', 'medida', 'restaurante_id'];
public static function findOrFail($id) {
$ingrediente = Ingrediente::find($id);
if(!$ingrediente) throw new ModelNotFoundException("ingrediente", $id);
return $ingrediente;
}
public function recetas() {
return $this->hasMany(Receta::class, 'ingrediente_id');
}
public function restaurante() {
return $this->belongsTo(Restaurante::class);
}
}