mohamed7sameer / countries-laravel
为Laravel提供的国家信息
v1
2023-10-09 13:01 UTC
Requires
- mohamed7sameer/countries: >=0.5.8
Requires (Dev)
- colinodell/json5: ^1.0
- gasparesganga/php-shapefile: ^2.3
- orchestra/testbench: ~3.0|~4.0|~5.0
- phpunit/phpunit: ~6.0|~7.0|~8.0|~9.0
- squizlabs/php_codesniffer: ^2.3
README
为Laravel提供的国家信息
它为你提供了什么?
此包包含有关国家的各种信息
验证
验证扩展了Laravel的验证功能,因此您可以像使用其他验证规则一样使用它,例如
/** * Store a new blog post. * * @param Request $request * @return Response */ public function store(Request $request) { $this->validate($request, [ 'title' => 'required|unique:posts|max:255', 'body' => 'required', 'country' => 'country' //Checks if valid name.common ]); // The blog post is valid, store in database... }
哪些验证规则及其名称可以在配置文件中进行配置。
'validation' => [ 'rules' => [ 'countryCommon' => 'name.common' ] ]
通过更改配置如下,我们现在可以通过验证规则countryCommon
访问属性name.common
您必须在设置中定义所有验证规则,默认情况下定义的很少,默认为
'rules' => [ 'country' => 'name.common', 'cca2', 'cca3', 'ccn3', 'cioc', 'currencies' => 'ISO4217', 'language', 'language_short' => 'ISO639_3', ]
文档
此包是Laravel桥接器,请参阅主要包仓库以获取更多信息以及文档。
要求
- PHP 7.0+
- Laravel 5.5+
安装
使用Composer安装
composer require mohamed7sameer/countries-laravel
发布资源
您可以通过以下方式发布配置
php artisan vendor:publish --provider=Mohamed7sameer\\CountriesLaravel\\Package\\ServiceProvider
使用方法
安装后,您将能够访问国家外观,并且该包基于Laravel集合,因此您基本上可以访问集合中的所有方法,如
$france = Countries::where('name.common', 'France');
国旗路由
您可以直接通过链接引用SVG国旗
/mohamed7sameer/countries/flag/download/<cca3-code>.svg
/mohamed7sameer/countries/flag/file/<cca3-code>.svg
示例
https://laravel.net.cn/mohamed7sameer/countries/flag/download/usa.svg
https://laravel.net.cn/mohamed7sameer/countries/flag/file/usa.svg
http://mohamed7sameer.test/mohamed7sameer/countries/flag/file/usa.svg
这些路由可以在配置文件中关闭
'routes' => [ 'enabled' => false, ]
作者
许可
Countries遵循MIT许可证 - 请参阅LICENSE
文件以获取详细信息
贡献
欢迎提交拉取请求和问题。