定制 leonardofilhogm/eloquent-countries 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

leonardofilhogm/eloquent-countries

Composer 安装命令:

composer require leonardofilhogm/eloquent-countries

包简介

Sushi-backed Eloquent countries data and validation rules for Laravel.

README 文档

README

Sushi-backed Eloquent countries data and validation rules for Laravel. The full country dataset is baked into the package — no migrations, no database table, no seeders required.

Installation

composer require trato/eloquent-countries

The service provider is auto-discovered. Optionally publish the config:

php artisan vendor:publish --tag=eloquent-countries-config

Usage

Querying countries

Trato\EloquentCountries\Models\Countries is a standard Eloquent model, so all query-builder methods work:

use Trato\EloquentCountries\Models\Countries;

Countries::all();
Countries::where('iso2', 'CH')->first();
Countries::where('iso3', 'BRA')->first();
Countries::where('region', 'Europe')->get();

Available columns include: name, official_name, native_name, official_native_name, iso2, iso3, numeric_code, dial_code, capital, region, sub_region, continent, tld, languages, borders, flag, zip_code, startOfWeek, emoji_flag.

Validation rules

use Trato\EloquentCountries\Rules\IsValidCountryCode;   // ISO 3166-1 alpha-2
use Trato\EloquentCountries\Rules\IsValidCountryCode3;  // ISO 3166-1 alpha-3

$request->validate([
    'country'      => ['required', new IsValidCountryCode],
    'country_iso3' => ['required', new IsValidCountryCode3],
]);

Data source

Country data is sourced from restcountries.com. Automatic refresh is disabled — the dataset is baked into the package and updated manually on release. To refresh, re-pull from restcountries.com, update src/Models/Countries.php, and tag a new release.

Caching (Sushi)

This package uses Sushi, which caches the country rows in a local SQLite store. After upgrading the package (when the underlying data changes), clear the Sushi cache so the new rows are picked up:

php artisan cache:clear

If rows still look stale, delete the cached SQLite file Sushi generated for the Countries model (in your framework's cache/storage path) and let it rebuild.

Testing

composer install
composer test

License

MIT

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-29

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固