elsayed85 / laravel-country-state-city
Laravel 国家、州和城市集合。
dev-master
2023-06-03 18:42 UTC
Requires
- php: ^8.1
This package is auto-updated.
Last update: 2024-09-03 21:09:56 UTC
README
为 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 以获取详细信息。