slatyo / laravel-pokemontcg
pokemontcg.io API 的包装器
Requires
- php: ^8.0
- guzzlehttp/guzzle: ^7.4
- illuminate/support: ^8.0
Requires (Dev)
- mockery/mockery: ^1.4
- nunomaduro/collision: ^5.10
- nunomaduro/larastan: ^0.7.15
- orchestra/testbench: ^6.0
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
README
此包是一个简单的 API Laravel 包装器,用于 Pokemontcg,具有优雅的模型设计,用于 API 路由和身份验证。
安装
您可以通过 composer 安装此包
composer require slatyo/laravel-pokemontcg
此包将自动注册其服务提供者。
要发布配置文件到 config/pokemontcg.php,请运行
php artisan vendor:publish --provider="Slatyo\LaravelPokemontcg\LaravelPokemontcgServiceProvider"
config/pokemontcg.php 的默认内容
<?php /* * Default configuration to run the pokemontcg.io API */ return [ 'url' => env('POKEMONTCG_API_URL', 'https://api.pokemontcg.io/v2'), 'secret' => env('POKEMONTCG_SECRET'), ];
用法
Pokemontcg
Slatyo\LaravelPokemontcg\Pokemontcg 是默认包装器,用于访问 Pokemontcg API 提供的所有功能。
支持的模型
卡片
要访问卡片模型,您必须调用
$cards = Pokemontcg::cards();
按 id 查找
通过其 id 查找特定卡片
$cards->find('Test-111'); // or use \Slatyo\LaravelPokemontcg\Facades\Card; Card::find('Test-111');
按 hp 搜索 ($from, $to)
根据 HP 查找宝可梦
$from = "1"; $to = "100"; $cards->hp($from, $to); // or use \Slatyo\LaravelPokemontcg\Facades\Card; Card::hp($from, $to); Card::whereHp($from, $to); // alias
按名称搜索
根据名称查找宝可梦
$cards->name('Charizard'); // or use \Slatyo\LaravelPokemontcg\Facades\Card; Card::name('Charizard'); Card::whereName('Charizard'); // alias
按宝可梦图鉴条目搜索 ($from, $to)
根据名称查找宝可梦
$from = "1"; $to = "151"; $cards->pokedex($from, $to); // or use \Slatyo\LaravelPokemontcg\Facades\Card; Card::pokedex($from, $to); Card::wherePokedex($from, $to); // alias
按超类型搜索
根据 supertypes 和 types 查找宝可梦
$cards->supertype('mega'); $cards->supertype('mega', 'water'); // or use \Slatyo\LaravelPokemontcg\Facades\Card; Card::supertype('mega'); Card::supertype('mega', 'water'); Card::whereSupertype('mega'); // alias Card::whereSupertype('mega', 'water'); // alias
搜索查询
根据查询字符串搜索宝可梦 - 更多关于查询如何工作的详细信息,请查看: Pokemontcg 搜索卡片。
$cards->search('name:Char*zard supertype:mega -type:fire'); // or use \Slatyo\LaravelPokemontcg\Facades\Card; Card::search('name:Char*zard supertype:mega -type:fire');
系列
要访问系列模型,您必须调用
$sets = Pokemontcg::sets();
按 id 查找
按 id 查找特定系列
$sets->find('set-name'); // or use \Slatyo\LaravelPokemontcg\Facades\Set; Set::find('set-name');
搜索查询
根据查询字符串搜索宝可梦系列 - 更多关于查询如何工作的详细信息,请查看: Pokemontcg 搜索系列。
$sets->search('legalities.standard:legal'); // or use \Slatyo\LaravelPokemontcg\Facades\Set; Set::search('legalities.standard:legal');
超类型
要访问超类型模型,您必须调用
$supertypes = Pokemontcg::supertypes();
获取所有
返回所有 supertypes
$supertypes->all(); // or use \Slatyo\LaravelPokemontcg\Facades\Supertype; Supertype::all();
子类型
要访问子类型模型,您必须调用
$subtypes = Pokemontcg::subtypes();
获取所有
返回所有 subtypes
$subtypes->all(); // or use \Slatyo\LaravelPokemontcg\Facades\Subtype; Subtype::all();
类型
要访问子类型模型,您必须调用
$types = Pokemontcg::types();
获取所有
返回所有 types
$types->all(); // or use \Slatyo\LaravelPokemontcg\Facades\Type; Type::all();
稀有度
要访问稀有度模型,您必须调用
$rarities = Pokemontcg::rarities();
获取所有
返回所有 rarities
$rarities->all(); // or use \Slatyo\LaravelPokemontcg\Facades\Rarity; Rarity::all();
测试
执行测试台
composer test
运行 PHPStan
composer stan
在 windows 上运行 PHPStan
composer stan-2g
生成覆盖率报告
composer test:coverage composer test:coverage-html
变更日志
有关最近更改的更多信息,请参阅 CHANGELOG。
贡献
有关详细信息,请参阅 CONTRIBUTING。
安全
如果您发现任何安全相关的问题,请通过电子邮件 daniel.henze@outlook.com 而不是使用问题跟踪器。
鸣谢
- Daniel Henze
- 所有贡献者
- 此包是使用 Laravel Package Boilerplate 生成的。
许可
MIT 许可证 (MIT)。请参阅 许可文件 以获取更多信息。