jaynilsavani/laravel-country-state-city

Laravel国家、州和城市集合。

1.1.0 2022-01-24 17:25 UTC

This package is auto-updated.

Last update: 2024-09-24 17:34:01 UTC


README

Total Downloads License

世界各地的国家、州和城市提供者,适用于Laravel。

安装

对于Laravel 8,运行以下命令:

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

对于Laravel 7,运行以下命令:

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

为了发布配置,

php artisan world:publish

用法

从国家获取所有数据

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; 

许可

本软件包遵循MIT许可证。请参阅许可证文件以获取更多详细信息。

贡献

有关详细信息,请参阅CONTRIBUTING