<?php

namespace Predial;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class ciudad extends Model
{
    public    $table      = "gf_ciudad";
    protected $primaryKey = 'id_unico';

    public $fillable = [
        'id_unico',
        'nombre',
        'departamento'
    ];

    protected $casts = [
        'id_unico'     => 'integer',
        'nombre'       => 'string',
        'departamento' => 'integer'
    ];

    public static function obtnerCiudades(){
        $data = DB::table('gf_ciudad as city')
                ->select('city.id_unico', 'city.nombre', 'dept.nombre as ndpt')
                ->leftJoin('gf_departamento as dept', 'city.departamento', '=', 'dept.id_unico')
                ->orderBy('city.nombre', 'asc')
                ->get();

        return $data;
    }
}
