kfoobar/laravel-sportmonks-soccer

Laravel package for Sportmonks Soccer API v2.0. Fork of kirill-latish/laravel-sportmonks-soccer

v1.0.0 2022-09-21 12:32 UTC

This package is auto-updated.

Last update: 2024-04-21 15:58:01 UTC


README

This package is a wrapper for Sportmonks Soccer API for Laravel 7/8/9.

This is a fork of kirill-latish/laravel-sportmonks-soccer with added support for Larvel 7+.

Installation

Install the package via Composer:

composer require kfoobar/laravel-sportmonks-soccer

Add your API token to your .env file:

SPORTMONKS_API_TOKEN=

For more settings, you can publish the config file:

$ php artisan vendor:publish --provider="Sportmonks\SoccerAPI\SoccerAPIServiceProvider"

Usage

Example when using the facade:

use SoccerAPI;

...

$response = SoccerAPI::leagues()->all();
$response = SoccerAPI::fixtures()->byId($id);

Relations

If you need to include other relations (check the official documentation for which relations can be included):

$response = SoccerAPI::seasons()->setInclude(['league', 'fixtures'])->all();

Response

The default behaviour is to return an object containing a data array:

$response = SoccerAPI::fixtures()->byId($id);

var_dump($response->data);
{
    "data": [
        {
            "id": null,
            "league_id": null,
            "scores": {
                "localteam_score": 0,
                "visitorteam_score": 0
            }
        }
    ]
}

If you want to directly retrieve the properties inside data, set skip_data to true in your config file.

$response = SoccerAPI::fixtures()->byId($id);

var_dump($response);
{
    "id": null,
    "league_id": null,
    "scores": {
        "localteam_score": 0,
        "visitorteam_score": 0
    }
}

Documentation

Please refer to the official documentation as to which API calls can be made.

Contributing

Thank you for considering contributing!