PHP code example of rickwest / laravel-sportspress-api

1. Go to this page and download the library: Download rickwest/laravel-sportspress-api 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/ */

    

rickwest / laravel-sportspress-api example snippets


// Without the package 👎
Http::get('https://example.com/wp-json/sportspress/v2/players', [
    'search' => 'lebron',
    '_embed' => 1,
    'orderby' => 'date',
    'order' => 'desc'
    '_fields' => 'title',
]);


// Using the package 👌
SportsPress::players()
    ->search('lebron')
    ->embed()
    ->latest()
    ->get('title');

// Without the package 👎
$response = Http::get('https://example.com/wp-json/sportspress/v2/players');
$data = $response->json();
$pages = $response->header('X-WP-TotalPages');
$total = $response->header('X-WP-Total');


// Using the package 👌
$players = SportsPress::players()->get();

// $posts
[
    'data' => [...],
    'meta' => [
        'pages' => 1,
        'total' => 10,
    ],
],


// Resolve service directly from container and access the Players API
app(SportsPress::class)->players();

// Resolve via Facade and access the Players API
SportsPress::players(); 

// Resolve service via helper and access the Players API
sportspress()->players();

// Supported resources
SportsPress::calendars() // Access the Calendars API
SportsPress::events() // Access the Events API
SportsPress::leagues() // Access the Leagues API
SportsPress::players() // Access the Players API
SportsPress::postitions() // Access the Positions API
SportsPress::roles() // Access the Roles API
SportsPress::seasons() // Access the Seasons API
SportsPress::staff() // Access the Staff API
SportsPress::teams() // Access the Teams API
SportsPress::venues() // Access the Venues API

// You can also access resources as properties
sportspress()->players

SportsPress::players()->find(1);

SportsPress::players()->get();

SportsPress::players()->send(string $method, int $id, array $options);