<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

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

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