PHP code example of jaynilsavani / laravel-country-state-city

1. Go to this page and download the library: Download jaynilsavani/laravel-country-state-city 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/ */

    

jaynilsavani / laravel-country-state-city example snippets


use App\Models\Country;

// To get all the countries
$countries = Country::all();


// To get all the states from country
$states = Country::where('name','india')->first()->states; 
$stateNames = Country::where('name','india')->first()->states->pluck('name');


// To get all the cities from country
$cities = Country::where('name','india')->first()->cities; 
$cityNames = Country::where('name','india')->first()->cities->pluck('name');

use App\Models\State;

// Retrieve all the states
$states = State::all();


// Retrieve country of any state
$country = State::where('name','quebec')->first()->country; 


// Retrieve all the cities of any state
$cities = State::where('name','quebec')->first()->cities; 

use App\Models\City;

// Retrieve all the cities
$cities = City::all();


// Retrieve state of any city
$state = City::where('name','montreal')->first()->state; 


// Retrieve country of any city
$country = City::where('name','montreal')->first()->state->country; 

php artisan world:publish