<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class MstNewsCategory extends Model
{
    //
        //
        public static function getData($code='') 
        {
            if($code==''){
                $types = MstNewsCategory::get();
    
                $arrResult = array();
                foreach($types as $type){
                     $arrResult[] = ['code' => $type->code, 'name' => $type->name];
                }
                return $arrResult;         
            } else {
                $types = MstNewsCategory::where('code', '=', $code)->get();
                
                $arrResult = array();
                foreach($types as $type){
                     $arrResult[] = ['code' => $type->code, 'name' => $type->name];
                }
                return $arrResult;
            }
        }

        public static function getDataArray($code='') 
        {
            $types = MstNewsCategory::get();
    
            $arrResult = array();
            foreach($types as $type){
                    $arrResult[$type->code] = $type->name;
            }
            return $arrResult;    
        }
}
