pragmarx /countries-laravel
Laravel 的国家信息
v0.7.0
2020-03-26 09:17 UTC
Requires
- php: >=7.0
- laravel/framework: >=5.3
- pragmarx/coollection: >=0.6
- pragmarx/countries: >=0.5.8
- psr/simple-cache: ^1.0
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 pragmarx/countries-laravel
发布资产
您可以通过以下方式发布配置
php artisan vendor:publish --provider=PragmaRX\\CountriesLaravel\\Package\\ServiceProvider
使用方法
安装后,您将能够访问 Countries Façade,此包基于 Laravel Collections,因此您基本上可以访问 Collections 中的所有方法,例如
$france = Countries::where('name.common', 'France');
旗帜路由
您可以直接通过链接引用 SVG 旗帜
/pragmarx/countries/flag/download/<cca3-code>.svg
/pragmarx/countries/flag/file/<cca3-code>.svg
示例
https://laravel.net.cn/pragmarx/countries/flag/download/usa.svg
https://laravel.net.cn/pragmarx/countries/flag/file/usa.svg
http://pragmarx.test/pragmarx/countries/flag/file/usa.svg
这些路由可以在配置文件中关闭
'routes' => [ 'enabled' => false, ]
作者
许可
Countries 在 MIT 许可证下发布 - 请参阅 LICENSE
文件以获取详细信息
贡献
欢迎提交拉取请求和问题。