public function countries($by = null, $value = null)
    {
        $countries = json_decode(file_get_contents(__DIR__ . '/../../data/countries.json'), true);

        if (is_null($by) && is_null($value)) {
            $countries = collect($countries)->values()->all();
        } else {
            if ($by == 'locale') {
                $value = str_replace(' ', '_', $value);
                $value = str_replace('-', '_', $value);
            }

            if ($by == 'locale' && strlen($value) == 2) {
                if ($value == 'en') {
                    $value = 'en_US';
                } elseif ($value == 'br') {
                    $value = 'pt_BR';
                } else {
                    $value = $value.'_'.strtoupper($value);
                }
            }

            $countries = (object) collect($countries)->filter(function ($item) use ($by, $value) {
                return strtolower($item[$by]) == strtolower($value);
            })->values()->first();
        }

        return $countries;
    }
public function countries($by = null, $value = null)
    {
        $countries = json_decode(file_get_contents(__DIR__ . '/../../data/countries.json'), true);

        if (is_null($by) && is_null($value)) {
            $countries = collect($countries)->values()->all();
        } else {
            if ($by == 'locale') {
                $value = str_replace(' ', '_', $value);
                $value = str_replace('-', '_', $value);
            }

            if ($by == 'locale' && strlen($value) == 2) {
                if ($value == 'en') {
                    $value = 'en_US';
                } elseif ($value == 'br') {
                    $value = 'pt_BR';
                } else {
                    $value = $value.'_'.strtoupper($value);
                }
            }

            $countries = (object) collect($countries)->filter(function ($item) use ($by, $value) {
                return strtolower($item[$by]) == strtolower($value);
            })->values()->first();
        }

        return $countries;
    }
public function countries ( $ by = null , $ value = null ) { $ countries = json_decode ( file_get_contents ( __DIR__ . '/../../data/countries.json' ) , true ) ; if ( is_null ( $ by ) && is_null ( $ value ) ) { $ countries = collect ( $ countries ) -> values ( ) -> all ( ) ; } else { if ( $ by == 'locale' ) { $ value = str_replace ( ' ' , '_' , $ value ) ; $ value = str_replace ( '-' , '_' , $ value ) ; } if ( $ by == 'locale' && strlen ( $ value ) == 2 ) { if ( $ value == 'en' ) { $ value = 'en_US' ; } elseif ( $ value == 'br' ) { $ value = 'pt_BR' ; } else { $ value = $ value . '_' . strtoupper ( $ value ) ; } } $ countries = ( object ) collect ( $ countries ) -> filter ( function ( $ item ) use ( $ by , $ value ) { return strtolower ( $ item [ $ by ] ) == strtolower ( $ value ) ; } ) -> values ( ) -> first ( ) ; } return $ countries ; }
Countries search and list
@param  string $by    Column to search (locale, name, shortname, slug)
@param  string $value Value to search
@return array
Countries search and list