PHP code example of flairuk / laravel-cities

1. Go to this page and download the library: Download flairuk/laravel-cities library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

flairuk / laravel-cities example snippets


use FLAIRUK\Cities\Facades\Cities;

Cities::find('lon');             // City { id: 4241, code: "LON", name: "London", countryCode: "GB" }
Cities::findOrFail('LON');       // throws ItemNotFoundException for unknown codes
Cities::exists('NYC');           // true
Cities::findById(4241);

Cities::all();                   // Collection<string, City> keyed by code
Cities::inCountry('FR');         // cities in France
Cities::search('london');        // matches on name or exact code
Cities::codes();

Cities::options();               // ['LON' => 'London', ...] sorted by name
Cities::options('id');           // [4241 => 'London', ...]

use FLAIRUK\Cities\Rules\CityCode;

$request->validate(['city' => ['

$this->call(\FLAIRUK\Cities\Database\CitiesSeeder::class);

use FLAIRUK\Cities\Models\City;

City::code('LON')->first();
City::inCountry('GB')->orderBy('name')->get();

Schema::table('cities', fn (Blueprint $table) => $table->renameColumn('iso_3166_3', 'code'));