PHP code example of izaghar / xivapi-laravel

1. Go to this page and download the library: Download izaghar/xivapi-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

izaghar / xivapi-laravel example snippets


// config/xivapi.php
return [
    'language' => env('XIVAPI_LANGUAGE'),
    'game_version' => env('XIVAPI_GAME_VERSION'),
    'schema' => env('XIVAPI_SCHEMA'),
    'localizations' => env('XIVAPI_LOCALIZATIONS'),
];

use XivApi\Laravel\Facades\XivApi;

// Fetch an item
$item = XivApi::sheet('Item')->row(4)->get();

// Search with query string
$results = XivApi::search()
    ->query('+Name~"Potion" +LevelItem>=10')
    ->sheets(['Item'])
    ->get();

// Search with SearchQuery builder
use XivApi\Query\SearchQuery;

$results = XivApi::search()
    ->query(SearchQuery::where('Name')->contains('Potion'))
    ->sheets(['Item'])
    ->get();

// Override global settings per-request
$item = XivApi::sheet('Item')
    ->row(4)
    ->language(Language::German)
    ->get();

use XivApi\XivApi;

class ItemController extends Controller
{
    public function show(XivApi $api, int $id)
    {
        return $api->sheet('Item')->row($id)->get();
    }
}

$api = app(XivApi::class);
$item = $api->sheet('Item')->row(4)->get();

// Or using the alias
$api = app('xivapi');

use Spatie\LaravelData\Data;
use XivApi\Laravel\Normalizers\XivApiNormalizer;

class ItemData extends Data
{
    public function __construct(
        public int $rowId,
        public array $fields,
    ) {}

    public static function normalizers(): array
    {
        return [
            XivApiNormalizer::class,
        ];
    }
}

use XivApi\Laravel\Facades\XivApi;

$response = XivApi::sheet('Item')->row(4)->get();
$item = ItemData::from($response);

// config/data.php
return [
    'normalizers' => [
        \XivApi\Laravel\Normalizers\XivApiNormalizer::class,
        \Spatie\LaravelData\Normalizers\ModelNormalizer::class,
        \Spatie\LaravelData\Normalizers\ArrayableNormalizer::class,
        \Spatie\LaravelData\Normalizers\ObjectNormalizer::class,
        \Spatie\LaravelData\Normalizers\ArrayNormalizer::class,
        \Spatie\LaravelData\Normalizers\JsonNormalizer::class,
    ],
];
bash
php artisan vendor:publish --tag=xivapi-config