* @copyright 2020 MyAAC * @link https://my-aac.org */ use MyAAC\Models\Town; /** * Class Towns */ class Towns { /** * @var string */ private static $filename = CACHE . 'towns.php'; /** * Determine towns * * @return array */ public static function determine() { global $db; if($db->hasTable('towns')) { return self::getFromDatabase(); } return self::getFromOTBM(); } /** * Load cached towns file */ public static function load() { $towns = config('towns'); if (file_exists(self::$filename)) { $towns = require self::$filename; } config(['towns', $towns]); } /** * Save into cache file * * @return bool */ public static function save() { $towns = self::determine(); if (count($towns) > 0) { file_put_contents(self::$filename, 'load(); $towns = $townsReader->get(); } return $towns; } /** * Load from database * * @return array */ public static function getFromDatabase() { return Town::pluck('name', 'id')->toArray(); } }