public static function country(string $country, string $accessor, string $only_accessor = null) : Collection
    {
        $country = strtolower($country);
        $accessor = strtolower($accessor);
        $file = __DIR__ . "/../Assets/topojson/countries/{$country}/{$country}-{$accessor}.json";

        if (!file_exists($file)) {
            return Collection::make([]);
        }

        $json = json_decode(file_get_contents($file), true)['objects'];
        $key = array_keys($json)[0];

        return Collection::make($json[$key]['geometries'])->map(function ($country) use ($only_accessor) {
            if ($only_accessor) {
                return $country['properties'][$only_accessor];
            }

            return $country['properties'];
        });
    }
public static function country(string $country, string $accessor, string $only_accessor = null) : Collection
    {
        $country = strtolower($country);
        $accessor = strtolower($accessor);
        $file = __DIR__ . "/../Assets/topojson/countries/{$country}/{$country}-{$accessor}.json";

        if (!file_exists($file)) {
            return Collection::make([]);
        }

        $json = json_decode(file_get_contents($file), true)['objects'];
        $key = array_keys($json)[0];

        return Collection::make($json[$key]['geometries'])->map(function ($country) use ($only_accessor) {
            if ($only_accessor) {
                return $country['properties'][$only_accessor];
            }

            return $country['properties'];
        });
    }
public static function country ( string $ country , string $ accessor , string $ only_accessor = null ) : Collection { $ country = strtolower ( $ country ) ; $ accessor = strtolower ( $ accessor ) ; $ file = __DIR__ . "/../Assets/topojson/countries/{$country}/{$country}-{$accessor}.json" ; if ( ! file_exists ( $ file ) ) { return Collection :: make ( [ ] ) ; } $ json = json_decode ( file_get_contents ( $ file ) , true ) [ 'objects' ] ; $ key = array_keys ( $ json ) [ 0 ] ; return Collection :: make ( $ json [ $ key ] [ 'geometries' ] ) -> map ( function ( $ country ) use ( $ only_accessor ) { if ( $ only_accessor ) { return $ country [ 'properties' ] [ $ only_accessor ] ; } return $ country [ 'properties' ] ; } ) ; }
Return the country information based on the accessor.

@author Erik Campobadal Fores <soc@erik.cat>
@copyright 2017 erik.cat
@param string $country
@param string $accessor
@param string|null $only_accessor
@return Collection
Return the country information based on the accessor .