<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MstUseDistrict extends Model
{
    //
    public static function getData($code='') 
    {
        if($code==''){
            $districts = MstUseDistrict::get();

            $arrResult = array();
            foreach($districts as $district){
                 $arrResult[] = ['code' => $district->code, 'name' => $district->name];
            }
            return $arrResult;         
        } else {
            $districts = MstUseDistrict::where('code', '=', $code)->get();
            
            $arrResult = array();
            foreach($districts as $district){
                 $arrResult[] = ['code' => $district->code, 'name' => $district->name];
            }
            return $arrResult;
        }
    }
}
