slatyo/laravel-pokemontcg

A wrapper for the pokemontcg.io API

1.2.1 2024-02-06 14:28 UTC

This package is auto-updated.

Last update: 2024-05-06 14:55:50 UTC


README

Latest Version on Packagist Total Downloads run-tests CodeFactor codecov

This package is a simple API laravel wrapper for Pokemontcg with a sleek Model design for API routes and authentication.

Installation

You can install the package via composer:

composer require slatyo/laravel-pokemontcg

The package will automatically register its service provider.

To publish the config file to config/pokemontcg.php run:

php artisan vendor:publish --provider="Slatyo\LaravelPokemontcg\LaravelPokemontcgServiceProvider"

Default content of 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'),
];

Usage

Pokemontcg

Slatyo\LaravelPokemontcg\Pokemontcg is the default wrapper to access everything the Pokemontcg API has to offer.

Supported Models

Cards

To access the cards model you have to call:

$cards = Pokemontcg::cards();
Find by id

Find a specific card by its id:

$cards->find('Test-111');

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::find('Test-111');
Search by hp ($from, $to)

Find Pokémon's based on HP:

$from = "1";
$to   = "100";
$cards->hp($from, $to);

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::hp($from, $to);
Card::whereHp($from, $to); // alias
Search by name

Find Pokémon's based on their name:

$cards->name('Charizard');

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::name('Charizard');
Card::whereName('Charizard'); // alias
Search Pokémon by Pokédex entries ($from, $to)

Find Pokémon's based on their name:

$from = "1";
$to   = "151";
$cards->pokedex($from, $to);

// or

use \Slatyo\LaravelPokemontcg\Facades\Card;

Card::pokedex($from, $to);
Card::wherePokedex($from, $to); // alias
Search by supertypes

Find Pokémon's by supertypes and 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
Search query

Search Pokémon's based on a query string - for more details on how the query works check out: Pokemontcg search cards.

$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

To access the sets model you have to call:

$sets = Pokemontcg::sets();
Find by id

Find a specific set by its id:

$sets->find('set-name');

// or

use \Slatyo\LaravelPokemontcg\Facades\Set;

Set::find('set-name');
Search query

Search Pokémon sets based on a query string - for more details on how the query works check out: Pokemontcg search sets.

$sets->search('legalities.standard:legal');

// or

use \Slatyo\LaravelPokemontcg\Facades\Set;

Set::search('legalities.standard:legal');

Supertypes

To access the supertypes model you have to call:

$supertypes = Pokemontcg::supertypes();
Get all

Return all supertypes:

$supertypes->all();

// or

use \Slatyo\LaravelPokemontcg\Facades\Supertype;

Supertype::all();

Subtypes

To access the subtypes model you have to call:

$subtypes = Pokemontcg::subtypes();
Get all

Return all subtypes:

$subtypes->all();

// or

use \Slatyo\LaravelPokemontcg\Facades\Subtype;

Subtype::all();

Types

To access the subtypes model you have to call:

$types = Pokemontcg::types();
Get all

Return all types:

$types->all();

// or

use \Slatyo\LaravelPokemontcg\Facades\Type;

Type::all();

Rarities

To access the rarities model you have to call:

$rarities = Pokemontcg::rarities();
Get all

Return all rarities:

$rarities->all();

// or

use \Slatyo\LaravelPokemontcg\Facades\Rarity;

Rarity::all();

Testing

Executing the testbench:

composer test

Running PHPStan

composer stan

Running PHPStan on windows

composer stan-2g

Generate coverage reports

composer test:coverage
composer test:coverage-html

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email daniel.henze@outlook.com instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.