快看!这个Laravel World扩展支持中文!

藏色散人
藏色散人转载
2021-11-08 15:48:441203浏览

下面由Laravel教程栏目带大家推荐介绍关于Laravel World的扩展,希望对大家有所帮助!

Laravel World —— 自带数据库的国家以及城市数据(支持中文)

Laravel World (https://github.com/nnjeim/world)是一个提供国家、州、城市、货币和时区列表的包。 World 通过数据库将数据与 Eloquent 模型集成,并提供 Facades、helper 和 API 路由:

use Nnjeim\World\World;

$action =  World::countries();
/*
{
    "success": true,
    "message": "countries",
    "data": [
        {
            "id": 1,
            "name": "Afghanistan"
        },
        {
            "id": 2,
            "name": "Åland Islands"
        },
      ...
    ],
}
*/

这是 readme 中的另一个示例,使用过滤器来获取国家/地区和该国家/地区内的城市:

// 获取国家和城市
$action =  World::countries([
    'fields' => 'states,cities',
    'filters' => [
        'iso2' => 'FR',
    ]
]);
/*
{
    "success": true,
    "message": "countries",
    "data": [
        "id": 77,
        "name": "France",
        "states": [
             {
                "id": 1271,
                "name": "Alo"
            },
            {
                "id": 1272,
                "name": "Alsace"
            },
        ],
        "cities": [
            {
                "id": 25148,
                "name": "Abondance"
            },
            {
                "id": 25149,
                "name": "Abrest"
            },
            ...
        ]
    ],
}
*/

此包还支持本地化(请参阅 readme 以了解支持的语言环境),为所有数据提供 API,并具有辅助函数,如格式化电话号码等

您可以了解有关此软件包的更多信息、获取完整的安装说明并查看 GitHub 上的 源代码。(https://github.com/nnjeim/world)

此包已提交到我们的 Laravel 新闻链接 部分。 链接是社区可以围绕 Laravel 生态系统发布软件包和教程的地方。 在 Twitter 上关注 @LaravelLinks

原文地址:https://laravel-news.com/laravel-world

译文地址:https://learnku.com/laravel/t/62354

以上就是快看!这个Laravel World扩展支持中文!的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:learnku,如有侵犯,请联系admin@php.cn删除