项目作者: jaynilsavani

项目描述 :
Laravel Country, State and City collection.
高级语言: PHP
项目地址: git://github.com/jaynilsavani/laravel-country-state-city.git
创建时间: 2021-06-20T06:45:43Z
项目社区:https://github.com/jaynilsavani/laravel-country-state-city

开源协议:MIT License

下载


Laravel Country, State and City

Total Downloads License

World’s Country, State and City Provider for Laravel.

Installation

Run a command for Laravel 8,

  1. composer require jaynilsavani/laravel-country-state-city:1.0.0

Run a command for Laravel 7,

  1. composer require jaynilsavani/laravel-country-state-city:1.1.0

To publish configurations,

  1. php artisan world:publish

Usage

To get all the data from Country:

  1. use App\Models\Country;
  2. // To get all the countries
  3. $countries = Country::all();
  4. // To get all the states from country
  5. $states = Country::where('name','india')->first()->states;
  6. $stateNames = Country::where('name','india')->first()->states->pluck('name');
  7. // To get all the cities from country
  8. $cities = Country::where('name','india')->first()->cities;
  9. $cityNames = Country::where('name','india')->first()->cities->pluck('name');

To get all the data from State:

  1. use App\Models\State;
  2. // Retrieve all the states
  3. $states = State::all();
  4. // Retrieve country of any state
  5. $country = State::where('name','quebec')->first()->country;
  6. // Retrieve all the cities of any state
  7. $cities = State::where('name','quebec')->first()->cities;

To get all the data from City:

  1. use App\Models\City;
  2. // Retrieve all the cities
  3. $cities = City::all();
  4. // Retrieve state of any city
  5. $state = City::where('name','montreal')->first()->state;
  6. // Retrieve country of any city
  7. $country = City::where('name','montreal')->first()->state->country;

License

This package is licensed under the MIT License. Please see the License File for more details.

Contributing

Please see CONTRIBUTING for details.