<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class OrdenCompra extends Model
{
    use HasFactory;

    protected $table = 'ordenes_de_compra';    

    protected static function boot()
    {
        parent::boot();
        static::creating(function ($item) 
        {
            if (! $item->status) {
                $item->status = 'pendiente';
            }
        });
        static::updating(function ($item) 
        {
           if (! $item->status) {
                $item->status = 'pendiente';
            }
        });
    }
    
    public function insumo() 
    {
        return $this->belongsTo(Insumo::class, 'insumo_id');
    }

    public function proveedor() 
    {
        return $this->belongsTo(Proveedor::class, 'proveedor_id');
    }
}
