Files
unified-restaurant-original/backend/app/Models/Compra.php
2021-07-14 03:58:17 -04:00

40 lines
964 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 Compra extends Model {
use UuidPrimaryKey, SoftDeletes;
protected $table = 'compras';
protected $fillable = [
'id', 'fecha_compra', 'proveedor_id', 'en_arqueo', 'restaurante_id'
];
public static function findOrFail($id) {
$compra = Compra::find($id);
if(!$compra) throw new ModelNotFoundException("compra", $id);
return $compra;
}
public function ingredientes() {
return $this->hasMany(CompraIngrediente::class);
}
public function facturas() {
return $this->hasMany(Factura::class);
}
public function restaurante() {
return $this->belongsTo(Restaurante::class);
}
public function proveedor() {
return $this->belongsTo(Proveedor::class);
}
}