<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Municipio extends Model
{
    protected $table = 'ibge.municipios';
    protected $fillable = ['id', 'nome'];

    public function search($filter = null)
    {
        $results = $this->where(function ($query) use ($filter){
            if($filter){
                $query->where('nome', "$filter}");
            }
        })//->toSql();
        ->paginate();
        return $results;
    }

    public function lotes()
    {
        return $this->hasMany(Lote::class);
        //CASO FOSSE VINCULAR COM SITUAÇÃO JURÍDICA (ESSE id SERIA O id DA TABELA sige.situacoes_juridicas) - AULA 9
        // return $this->hasMany(Lote::class, 'municipio_id', 'id');
    }  

   

}
