kossa / algerian-cities
一个 Laravel 扩展包,用于创建/加载阿尔及利亚的省和市镇,包括阿拉伯语和法语语言,包含市镇的邮政编码和经纬度
v3.0.3
2024-07-08 17:28 UTC
Requires
- php: ^8.0|^8.1|^8.2|^8.3|^8.4
- laravel/framework: ^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^7.0
- phpstan/phpstan: ^1.0
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-08 17:51:01 UTC
README
这是一个 Laravel 扩展包,用于创建/加载阿尔及利亚的省和市镇,包括阿拉伯语和法语语言,包含市镇的邮政编码和经纬度
安装
composer require kossa/algerian-cities php artisan algerian-cities:install
使用此包
基本用法
有两个模型 Wilaya
和 Commune
,可以像任何模型一样导入和使用它们
namespace App; use Illuminate\Database\Eloquent\Model; use Kossa\AlgerianCities\Commune; use Kossa\AlgerianCities\Wilaya; class AnyClass extends Model { $wilayas = Wilaya::all(); // Get all wilayas $communes = Commune::all(); // Get all communes $algiers_communes = Commune::where('wilaya_id', 16)->get(); // get all communes of Algiers(16) }
通过助手函数
有多个助手函数,例如
$wilayas = wilayas(); // get all wilayas as $id => $name $wilayas = wilayas('arabic_name'); // get all wilayas in arabic $communes = communes(); // get all communes as $id => $name $communes = communes(16); // get all communes of Algiers(16) as $id => $name $communes = communes(16, $withWilaya = true); // get all communes of Algiers(16) with name of wilayas like : Alger Centre, Alger $communes = communes(16, $withWilaya = true, $name = "arabic_name"); // get all communes of Algiers(16) with name of wilayas in arabic like : الجزائر الوسطى, الجزائر $single_commune = commune(1); // get a single commune model $single_commune = commune(1, $withWilaya = true); // get a single commune model include wilaya $single_wilaya = wilaya(1); // get a single wilaya
Blade/视图
您可以使用上述任何助手/模型,并在选择中使用它
// wilayas <select> @foreach (wilayas() as $id => $wilaya) <option value="{{ $id }}">{{ $wilaya }}</option> @endforeach </select> // communes <select> @foreach (communes() as $id => $commune) <option value="{{ $id }}">{{ $commune }}</option> @endforeach </select> // communes of Algiers(16) <select> @foreach (communes($wilaya_id = 16) as $id => $commune) <option value="{{ $id }}">{{ $commune }}</option> @endforeach </select> // communes with wilaya name : Adrar, Adrar ... <select> @foreach (communes($wilaya_id = null, $withWilaya = true) as $id => $commune) <option value="{{ $id }}">{{ $commune }}</option> @endforeach </select> // communes with wilaya name in arabic : أدرار, أدرار ... <select> @foreach (communes($wilaya_id = null, $withWilaya = true, 'arabic_name') as $id => $commune) <option value="{{ $id }}">{{ $commune }}</option> @endforeach </select>
将包作为 API 使用
此包包含 api.php 路由以使用 API,以下是 URL
贡献
欢迎所有贡献,请遵循
- PSR-2 编码标准
- 记录任何行为变化 - 确保README.md和任何其他相关文档都保持最新。
- 每个功能一个拉取请求 - 如果您想做更多的事情,请发送多个拉取请求。
致谢
省/市镇的列表是从Wilaya-Of-Algeria收集的