<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

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

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