41 lines
1.0 KiB
PHP
41 lines
1.0 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 Compra extends Model {
|
|
use UuidPrimaryKey, SoftDeletes;
|
|
|
|
protected $table = 'compras';
|
|
protected $hidden = ['created_at', 'updated_at', 'deleted_at'];
|
|
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);
|
|
}
|
|
}
|