'required', 'code' => 'required', ]; /** * @var array Relations */ public $belongsTo = [ 'country' => ['RainLab\Location\Models\Country'] ]; /** * @var bool Indicates if the model should be timestamped. */ public $timestamps = false; /** * @var array Cache for nameList() method */ protected static $nameList = []; public static function getNameList($countryId) { if (isset(self::$nameList[$countryId])) { return self::$nameList[$countryId]; } return self::$nameList[$countryId] = self::whereCountryId($countryId)->isEnabled()->orderBy('name', 'asc')->lists('name', 'id'); } public function scopeIsEnabled($query) { return $query->where('is_enabled', true); } public static function formSelect($name, $countryId = null, $selectedValue = null, $options = []) { return Form::select($name, self::getNameList($countryId), $selectedValue, $options); } public static function getDefault() { return ($defaultId = Setting::get('default_state')) ? static::find($defaultId) : null; } }