<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Titulo extends Model
{
    protected $table = 'sige.titulos';
    protected $fillable = ['id', 'numero_titulo', 'gleba_id'];

    public function search($filter = null)
    {
        $results = $this->where(function ($query) use ($filter){
            if($filter){
                $query->where('numero_titulo', "{$filter}")
                ->orWhere('lote_id', "{$filter}")
                ->orWhere('gleba_id', "{$filter}");
            }
        })->paginate();
        return $results;
    }

    

    // public function lotes()
    // {
    //     return $this->belongsTo(Lote::class, 'lote_id', 'id');
    // }

    public function gleba()
    {
        return $this->belongsTo(Gleba::class, 'id');
    } 
    
}
