<?php

namespace App\Models;

use Auth;
use Illuminate\Database\Eloquent\Model;

class MstPrefecture extends Model
{
    //
    public static function getData($code = null, $company_id = null) 
    {
	$user = Auth::user();
    	$prefectures = MstPrefecture::query();
	
	if(!empty($code)) {
	    $prefectures->where('code', $code);
	}

	if($user) {
	   $company_id = $user->company_id;
	}
	
	if(!empty($company_id)) {
	    $prefectures->where('company_id', $company_id);
	}

	return $prefectures->select('code', 'name')
			->get()->toArray();
    }

    public static function getName($prefCode=null) 
    {
        $city_name = "";
        if($prefCode != null){
            $city_name = MstPrefecture::select('name')->where('code', '=', $prefCode)->first();
        }
        return $city_name;
    }
}
