CountryRegion::class includes a variety of PHP functions. Many of these functions are used by the package itself; however, you are free to use them in your own applications if you find them convenient.
Here you can explore the available methods to manipulate Region information as you wish. These methods provide a convenient way to filter, retrieve, and modify regions and their associated data within your application.
| Method | Description |
|---|---|
| countries() | Returns a list of countries filtered by the region. |
| whereSlug('americas') | Returns the region matching the specified slug 'americas'. |
| whereName('Americas') | Returns the region matching the specified name 'Americas'. |
| whereIso('AM') | Returns the region matching the specified ISO code 'AM'. |
| whereIsoAlpha2('AM') | Returns the region matching the specified ISO alpha-2 code 'AM'. |
| whereICAO('NAT') | Returns the region matching the specified ICAO code 'NAT'. |
| whereIUCN('Americas') | Returns the region matching the specified IUCN code 'Americas'. |
| whereTDWG('NAM/SAM') | Returns the region matching the specified TDWG code 'NAM/SAM'. |
Returns a list of countries filtered by the region.
->countries()
::: code-group
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::inRandomOrder()
->first()
->countries()
->get();
// Return a list of Country::class of a random CountryRegion::class
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereSlug('americas')
->first()
->countries()
->get();
// Return a list of Country::class of a CountryRegion::class with Americas information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereSlug('americas')
->first()
->countries()
->whereSlug('brazil')
->first();
// Return Country::class with Brazil information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereSlug('americas')
->first()
->countries()
# China is located in Asia
->whereSlug('china') // [!code warning]
->first();
// Return Null
:::
Returns the region matching the specified slug $slug.
->whereSlug(String $slug)
->orWhereSlug(String $slug)
::: code-group
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereSlug('europe')->first();
// Return CountryRegion::class with Europe information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereSlug('americas')->orWhereSlug('europe')->get();
// Return a list of CountryRegion::class with Europe and Americas information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereSlug('EuRoPe')->first();
// Return CountryRegion::class with Europe information
:::
Returns the region matching the specified name $name.
->whereName(String $name)
->orWhereName(String $name)
::: code-group
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereName('Europe')->first();
// Return CountryRegion::class with Europe information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereName('Americas')->orwhereName('Europe')->get();
// Return a list of CountryRegion::class with Europe and Americas information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereName('EUROPE')->first();
// Return CountryRegion::class with Europe information
:::
Returns the region matching the specified ISO code 'AM'.
whereIso is just an alias for whereIsoAlpha2, so you can use either one interchangeably to get the same result.
->whereIso(String $iso)
->orWhereIso(String $iso)
::: code-group
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereIso('EU')->first();
// Return CountryRegion::class with Europe information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereIso('AM')->orWhereIso('EU')->get();
// Return a list of CountryRegion::class with Europe and Americas information
:::
Returns the region matching the specified ISO alpha-2 code 'AM'.
->whereIsoAlpha2(String $alpha2)
->orWhereIsoAlpha2(String $alpha2)
::: code-group
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereIsoAlpha2('EU')->first();
// Return CountryRegion::class with Europe information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereIsoAlpha2('AM')->orWhereIsoAlpha2('EU')->get();
// Return a list of CountryRegion::class with Europe and Americas information
:::
Returns the region matching the specified ICAO code 'NAT'.
->whereICAO(String $icao)
->orWhereICAO(String $icao)
::: code-group
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereICAO('EUR')->first();
// Return CountryRegion::class with Europe information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereICAO('NAT')->orWhereICAO('EUR')->get();
// Return a list of CountryRegion::class with Europe and Americas information
:::
Returns the region matching the specified IUCN code 'Americas'.
->whereIUCN(String $iucn)
->orWhereIUCN(String $iucn)
::: code-group
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereIUCN('Europe')->first();
// Return CountryRegion::class with Europe information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereIUCN('Americas')->orWhereIUCN('Europe')->get();
// Return a list of CountryRegion::class with Europe and Americas information
:::
Returns the region matching the specified TDWG code 'NAM/SAM'.
->whereTDWG(String $tdwg)
->orwhereTDWG(String $tdwg)
::: code-group
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereTDWG('EUR')->first();
// Return CountryRegion::class with Europe information
use Lwwcas\LaravelCountries\Models\CountryRegion as Region;
Region::whereTDWG('NAM/SAM')->orWhereTDWG('EUR')->get();
// Return a list of CountryRegion::class with Europe and Americas information
:::
How can I help you explore Laravel packages today?