fpicosm/sportmonks-football-api

为 Sportmonks 足球 API 提供的 Laravel/Lumen 包装器

2.1.0 2024-05-03 17:07 UTC

This package is auto-updated.

Last update: 2024-09-03 17:54:12 UTC


README

安装

通过 composer 安装此包

composer require fpicosm/sportmonks-football-api

配置

更新你的 .env 文件,添加以下内容

SPORTMONKS_TOKEN=#YOUR_API_TOKEN#
SPORTMONKS_TIMEZONE=#YOUR_TIMEZONE#

SPORTMONKS_TIMEZONE 是可选的。如果不包括,则使用 APP_TIMEZONE 的值。

使用 Laravel

  1. config/app.phpproviders 部分中注册 ServiceProvider

    Sportmonks\FootballApi\FootballApiServiceProvider::class,
  2. 发布配置文件

    php artisan vendor:publish --provider="Sportmonks\FootballApi\FootballApiServiceProvider"

使用 Lumen

  1. 在项目根目录下创建 config 文件夹(如果尚不存在)。

  2. 创建文件 config/football-api.php 并粘贴以下内容

    <?php
    
    if (!function_exists('config_path')) {
        function config_path($path = '')
        {
            return app()->basePath() . '/config' . ($path ? "/$path" : $path);
        }
    }
    
    return [
        'token' => env('SPORTMONKS_TOKEN'),
        'timezone' => env('SPORTMONKS_TIMEZONE') ?: env('APP_TIMEZONE'),
    ];
  3. bootstrap/app.phpRegister Config Files 部分中添加配置文件

    $app->configure('football-api');
  4. bootstrap/app.phpRegister Service Providers 部分中添加 ServiceProvider

    $app->register(Sportmonks\FootballApi\FootballApiServiceProvider::class);
  5. bootstrap/app.php 中取消注释行 $app->withFacades();

用法

在需要的地方添加依赖

use Sportmonks\FootballApi\FootballApi;

然后,你可以调用

FootballApi::endpoint()->method($params):

选择选项

要选择特定字段,可以传递一个数组或逗号分隔的字符串。示例

FootballApi::countries()->select('name,official_name')->all();
FootballApi::countries()->select(['name', 'official_name'])->all();

包含选项

要包含关系,可以传递一个数组或分号分隔的字符串。示例

FootballApi::countries()->include('leagues;continent')->all();
FootballApi::countries()->include(['leagues', 'continent'])->all();

可以同时使用包含和选择选项。示例

FootballApi::continents()->include('countries:name,official_name')->select('name')->all();

分页

要设置页面编号,使用 page 方法

FootballApi::countries()->page(2)->all();

要设置页面大小,使用 perPage 方法

FootballApi::countries()->perPage(150)->all();

页面大小必须在 10150 之间(默认值为 100)。

端点

博彩公司

获取所有博彩公司

FootballApi::bookmakers()->all();

获取所有高级博彩公司

FootballApi::bookmakers()->premium();

通过 ID 获取博彩公司

FootballApi::bookmakers()->find($bookmakerId);

通过名称搜索博彩公司

FootballApi::bookmakers()->search($name);

通过比赛 ID 获取博彩公司

FootballApi::bookmakers()->byFixture($fixtureId);

通过比赛 ID 和博彩公司 ID 获取赛前赔率

FootballApi::bookmakers($bookmakerId)->preMatchOddsByFixture($fixtureId);

通过比赛 ID 和博彩公司 ID 获取实时赔率

FootballApi::bookmakers($bookmakerId)->inplayOddsByFixture($fixtureId);

通过比赛 ID 和博彩公司 ID 获取高级赔率

FootballApi::bookmakers($marketId)->premiumOddsByFixture($fixtureId);

城市

获取所有城市

FootballApi::cities()->all();

通过 ID 获取城市

FootballApi::cities()->find($cityId);

通过名称搜索城市

FootballApi::cities()->search($name);

教练

获取所有教练

FootballApi::coaches()->all();

通过 ID 获取教练

FootballApi::coaches()->find($coachId);

通过国家 ID 获取教练

FootballApi::coaches()->byCountry($countryId);

通过名称搜索教练

FootballApi::coaches()->search($name);

获取最后更新的教练

FootballApi::coaches()->lastUpdated();

通过赛季 ID 获取教练统计数据

FootballApi::coaches()->statisticsBySeason($seasonId);

评论

获取所有评论

FootballApi::commentaries()->all();

通过比赛 ID 获取评论

FootballApi::commentaries()->byFixture($fixtureId);

大陆

获取所有大陆

FootballApi::continents()->all();

通过 ID 获取大陆

FootballApi::continents()->find($continentId);

国家

获取所有国家

FootballApi::countries()->all();

通过 ID 获取国家

FootballApi::countries()->find($countryId);

通过名称搜索国家

FootballApi::countries()->search($name);

通过国家 ID 获取联赛

FootballApi::countries($countryId)->leagues();

通过国家 ID 获取球员

FootballApi::countries($countryId)->players();

通过国家 ID 获取球队

FootballApi::countries($countryId)->teams();

通过国家 ID 获取教练

FootballApi::countries($countryId)->coaches();

通过国家 ID 获取裁判

FootballApi::countries($countryId)->referees();

增强

获取所有增强

FootballApi::enrichments()->all();

期望

通过球队获取期望

FootballApi::expected()->byTeam();

通过球员获取期望

FootballApi::expected()->byPlayer();

过滤器

获取所有过滤器

FootballApi::filters()->all();

比赛

获取所有比赛

FootballApi::fixtures()->all();

通过 ID 获取比赛

FootballApi::fixtures()->find($fixtureId);

通过多个 ID 获取比赛

FootballApi::fixtures()->multiples([1, 2, 3, 4, 5]);
// or
FootballApi::fixtures()->multiples('1,2,3,4,5');

通过日期获取比赛

FootballApi::fixtures()->byDate($date);

通过日期范围获取比赛

FootballApi::fixtures()->byDateRange($from, $to);

通过日期范围获取球队的比赛

FootballApi::fixtures()->byDateRangeForTeam($from, $to, $teamId);

通过直接对话获取比赛

FootballApi::fixtures()->headToHead($firstTeamId, $secondTeamId);

通过名称搜索比赛

FootballApi::fixtures()->search($teamName);

通过市场 ID 获取即将进行的比赛

FootballApi::fixtures()->upcomingByMarket($marketId);

通过电视频道 ID 获取即将进行的比赛

FootballApi::fixtures()->upcomingByTvStation($tvStationId);

通过电视频道 ID 获取过去的比赛

FootballApi::fixtures()->pastByTvStation($tvStationId);

获取最后更新的比赛

FootballApi::fixtures()->lastUpdated();

通过比赛 ID 获取电视频道

FootballApi::fixtures($fixtureId)->tvStations();

通过比赛 ID 获取预测

FootballApi::fixtures($fixtureId)->predictions();

通过比赛 ID 获取博彩公司

FootballApi::fixtures($fixtureId)->bookmakers();

通过比赛 ID 获取评论

FootballApi::fixtures($fixtureId)->commentaries();

通过比赛 ID 获取价值投注

FootballApi::fixtures($fixtureId)->valueBets();

通过比赛 ID 获取赛前赔率

FootballApi::fixtures($fixtureId)->preMatchOdds();

通过比赛 ID 和博彩公司 ID 获取赛前赔率

FootballApi::fixtures($fixtureId)->preMatchOddsByBookmaker($bookmakerId);

通过比赛 ID 和市场 ID 获取赛前赔率

FootballApi::fixtures($fixtureId)->preMatchOddsByMarket($marketId);

通过比赛 ID 获取实时赔率

FootballApi::fixtures($fixtureId)->inplayOdds();

通过比赛 ID 和博彩公司 ID 获取实时赔率

FootballApi::fixtures($fixtureId)->inplayOddsByBookmaker($bookmakerId);

通过比赛 ID 和市场 ID 获取实时赔率

FootballApi::fixtures($fixtureId)->inplayOddsByMarket($marketId);

通过赛事ID获取高级赔率

FootballApi::fixtures($fixtureId)->premiumOdds();

通过比赛 ID 和博彩公司 ID 获取高级赔率

FootballApi::fixtures($fixtureId)->premiumOddsByBookmaker($bookmakerId);

通过赛事ID和市场ID获取高级赔率

FootballApi::fixtures($fixtureId)->premiumOddsByMarket($marketId);

联赛

获取所有联赛

FootballApi::leagues()->all();

通过ID获取联赛

FootballApi::leagues()->find($leagueId);

获取所有正在进行的联赛

FootballApi::leagues()->live();

通过赛事日期获取联赛

FootballApi::leagues()->byFixtureDate($date);

通过国家 ID 获取联赛

FootballApi::leagues()->byCountry($countryId);

通过名称搜索联赛

FootballApi::leagues()->search($name);

通过队伍ID获取所有联赛

FootballApi::leagues()->allByTeam($teamId);

通过队伍ID获取当前联赛

FootballApi::leagues()->currentByTeam($teamId);

通过联赛ID获取实时积分榜

FootballApi::leagues($leagueId)->liveStandings();

通过联赛ID获取预测

FootballApi::leagues($leagueId)->predictions();

实时比分

获取正在进行的实时比分

FootballApi::livescores()->inplay();

获取所有实时比分

FootballApi::livescores()->all();

获取最后更新的实时比分

FootballApi::livescores()->lastUpdated();

市场

获取所有市场

FootballApi::markets()->all();

获取所有高级市场

FootballApi::markets()->premium();

通过ID获取市场

FootballApi::markets()->find($marketId);

通过名称搜索市场

FootballApi::markets()->search($name);

通过比赛 ID 和市场 ID 获取赛前赔率

FootballApi::markets($marketId)->preMatchOddsByFixture($fixtureId);

通过比赛 ID 和市场 ID 获取实时赔率

FootballApi::markets($marketId)->inplayOddsByFixture($fixtureId);

通过赛事ID和市场ID获取高级赔率

FootballApi::markets($marketId)->premiumOddsByFixture($fixtureId);

新闻

获取所有赛前新闻

FootballApi::news()->all();

通过赛季ID获取赛前新闻

FootballApi::news()->bySeason($seasonId);

获取即将进行的赛事的赛前新闻

FootballApi::news()->upcoming();

实时赔率

获取所有实时赔率

FootballApi::oddsInplay()->all();

通过比赛 ID 获取实时赔率

FootballApi::oddsInplay()->byFixture($fixtureId);

通过比赛 ID 和博彩公司 ID 获取实时赔率

FootballApi::oddsInplay()->byFixtureAndBookmaker($fixtureId, $bookmakerId);

通过比赛 ID 和市场 ID 获取实时赔率

FootballApi::oddsInplay()->byFixtureAndMarket($fixtureId, $marketId);

获取最后更新的实时赔率

FootballApi::oddsInplay()->lastUpdated();

赛前赔率

获取所有赛前赔率

FootballApi::oddsPreMatch()->all();

通过比赛 ID 获取赛前赔率

FootballApi::oddsPreMatch()->byFixture($fixtureId);

通过比赛 ID 和博彩公司 ID 获取赛前赔率

FootballApi::oddsPreMatch()->byFixtureAndBookmaker($fixtureId, $bookmakerId);

通过比赛 ID 和市场 ID 获取赛前赔率

FootballApi::oddsPreMatch()->byFixtureAndMarket($fixtureId, $marketId);

获取最后更新的赛前赔率

FootballApi::oddsPreMatch()->lastUpdated();

高级赔率

获取所有高级赔率

FootballApi::oddsPremium()->all();

通过赛事ID获取高级赔率

FootballApi::oddsPremium()->byFixture($fixtureId);

通过比赛 ID 和博彩公司 ID 获取高级赔率

FootballApi::oddsPremium()->byFixtureAndBookmaker($fixtureId, $bookmakerId);

通过赛事ID和市场ID获取高级赔率

FootballApi::oddsPremium()->byFixtureAndMarket($fixtureId, $marketId);

获取时间段内更新的高级赔率

FootballApi::oddsPremium()->updatedBetween($from, $to);

获取时间段内历史高级赔率

FootballApi::oddsPremium()->historicalBetween($from, $to);

获取所有历史高级赔率

FootballApi::oddsPremium()->historical();

球员

获取所有球员

FootballApi::players()->all();

通过ID获取球员

FootballApi::players()->find($playerId);

通过国家 ID 获取球员

FootballApi::players()->byCountry($countryId);

通过名称搜索球员

FootballApi::players()->search($name);

获取最后更新的球员

FootballApi::players()->lastUpdated();

通过球员ID获取转会信息

FootballApi::players($playerId)->transfers();

通过赛季ID获取球员统计数据

FootballApi::players()->statisticsBySeason($seasonId);

预测

获取所有概率

FootballApi::predictions()->probabilities();

通过联赛ID获取预测的可预测性

FootballApi::predictions()->byLeague($leagueId);

通过赛事ID获取概率

FootballApi::predictions()->byFixture($fixtureId);

获取所有价值投注

FootballApi::predictions()->valueBets();

通过比赛 ID 获取价值投注

FootballApi::predictions()->valueBetsByFixture($fixtureId);

裁判

获取所有裁判

FootballApi::referees()->all();

通过ID获取裁判

FootballApi::referees()->find($refereeId);

通过国家 ID 获取裁判

FootballApi::referees()->byCountry($countryId);

通过名称搜索裁判

FootballApi::referees()->search($name);

通过赛季ID搜索裁判

FootballApi::referees()->bySeason($seasonId);

通过赛季ID获取裁判统计数据

FootballApi::referees()->statisticsBySeason($seasonId);

地区

获取所有地区

FootballApi::regions()->all();

通过ID获取地区

FootballApi::regions()->find($regionId);

通过名称搜索地区

FootballApi::regions()->search($name);

资源

获取所有资源

FootballApi::resources()->all();

竞争对手

获取所有竞争对手

FootballApi::rivals()->all();

通过队伍ID获取竞争对手

FootballApi::rivals()->byTeam($teamId);

轮次

获取所有轮次

FootballApi::rounds()->all();

通过ID获取轮次

FootballApi::rounds()->find($roundId);

通过赛季ID获取轮次

FootballApi::rounds()->bySeason($seasonId);

通过名称搜索轮次

FootballApi::rounds()->search($name);

通过轮次ID获取积分榜

FootballApi::rounds($roundId)->standings();

通过轮次ID获取统计数据

FootballApi::rounds($roundId)->statistics();

赛程

通过赛季ID获取赛程

FootballApi::schedules()->bySeason($seasonId);

通过队伍ID获取赛程

FootballApi::schedules()->byTeam($teamId);

通过赛季ID和队伍ID获取赛程

FootballApi::schedules()->bySeasonAndTeam($seasonId, $teamId);

赛季

获取所有赛季

FootballApi::seasons()->all();

通过ID获取赛季

FootballApi::seasons()->find($seasonId);

通过队伍ID获取赛季

FootballApi::seasons()->byTeam($teamId);

通过名称搜索赛季

FootballApi::seasons()->search($year);

通过赛季ID获取赛程

FootballApi::seasons($seasonId)->schedules();

通过赛季ID和队伍ID获取赛程

FootballApi::seasons($seasonId)->schedulesByTeam($teamId);

通过赛季ID获取阶段

FootballApi::seasons($seasonId)->stages();

通过赛季ID获取轮次

FootballApi::seasons($seasonId)->rounds();

通过赛季ID获取积分榜

FootballApi::seasons($seasonId)->standings();

通过赛季ID获取积分榜修正

FootballApi::seasons($seasonId)->standingsCorrection();

通过赛季ID获取最佳射手

FootballApi::seasons($seasonId)->topscorers();

通过赛季ID获取队伍

FootballApi::seasons($seasonId)->teams();

通过赛季ID和队伍ID获取阵容

FootballApi::seasons($seasonId)->squadsByTeam($teamId);

通过赛季ID获取场地

FootballApi::seasons($seasonId)->venues();

通过赛季ID获取新闻

FootballApi::seasons($seasonId)->news();

通过赛季ID获取裁判

FootballApi::seasons($seasonId)->referees();

通过赛季ID获取球员统计数据

FootballApi::seasons($seasonId)->playerStatistics();

通过赛季ID获取队伍统计数据

FootballApi::seasons($seasonId)->teamStatistics();

通过赛季 ID 获取教练统计数据

FootballApi::seasons($seasonId)->coachStatistics();

通过赛季ID获取裁判统计数据

FootballApi::seasons($seasonId)->refereeStatistics();

阵容

通过队伍ID获取当前国内阵容

FootballApi::squads()->byTeam($teamId);

通过队伍ID和当前赛季获取所有阵容

FootballApi::squads()->extendedByTeam($teamId);

通过队伍ID和赛季ID获取阵容

FootballApi::squads()->byTeamAndSeason($teamId, $seasonId);

阶段

获取所有阶段

FootballApi::stages()->all();

通过ID获取阶段

FootballApi::stages()->find($stageId);

通过赛季ID获取阶段

FootballApi::stages()->bySeason($seasonId);

通过名称搜索阶段

FootballApi::stages()->search($name);

通过阶段ID获取最佳射手

FootballApi::stages($stageId)->topscorers();

通过阶段ID获取统计数据

FootballApi::stages($stageId)->statistics();

积分榜

获取所有积分榜

FootballApi::standings()->all();

通过赛季ID获取积分榜

FootballApi::standings()->bySeason($seasonId);

通过赛季ID获取积分榜修正

FootballApi::standings()->correctionBySeason($seasonId);

通过轮次ID获取积分榜

FootballApi::standings()->byRound($roundId);

通过联赛ID获取实时积分榜

FootballApi::standings()->liveByLeague($leagueId);

状态

获取所有状态

FootballApi::states()->all();

通过ID获取状态

 FootballApi::states()->find($stateId);

统计数据

通过赛季ID获取球员统计数据

FootballApi::statistics()->playersBySeason($seasonId);

通过赛季ID获取队伍统计数据

FootballApi::statistics()->teamsBySeason($seasonId);

通过赛季 ID 获取教练统计数据

FootballApi::statistics()->coachesBySeason($seasonId);

通过赛季ID获取裁判统计数据

FootballApi::statistics()->refereesBySeason($seasonId);

通过阶段ID获取统计数据

FootballApi::statistics()->byStage($stageId);

通过轮次ID获取统计数据

FootballApi::statistics()->byRound($roundId);

队伍

获取所有队伍

FootballApi::teams()->all();

通过ID获取队伍

FootballApi::teams()->find($teamId);

通过国家 ID 获取球队

FootballApi::teams()->byCountry($countryId);

通过赛季ID获取队伍

FootballApi::teams()->bySeason($seasonId);

通过名称搜索队伍

FootballApi::teams()->search($name);

通过日期范围获取球队的比赛

FootballApi::teams($teamId)->fixturesByDateRange($from, $to);

通过头对头获取队伍的赛事

FootballApi::teams($teamId)->headToHead($opponentId);

通过队伍ID获取所有联赛

FootballApi::teams($teamId)->allLeagues();

通过队伍ID获取当前联赛

FootballApi::teams($teamId)->currentLeagues();

通过队伍ID获取赛程

FootballApi::teams($teamId)->schedules();

通过队伍ID和赛季ID获取赛程

FootballApi::teams($teamId)->schedulesBySeason($seasonId);

通过队伍ID获取赛季

FootballApi::teams($teamId)->seasons();

通过队伍ID获取当前国内阵容

FootballApi::teams($teamId)->squads();

通过队伍ID获取当前扩充阵容

FootballApi::teams($teamId)->extendedSquads();

通过队伍ID和赛季ID获取阵容

FootballApi::teams($teamId)->squadsBySeason($seasonId);

通过队伍ID获取转会信息

FootballApi::teams($teamId)->transfers();

通过队伍ID获取竞争对手

FootballApi::teams($teamId)->rivals();

通过赛季ID获取队伍统计数据

FootballApi::teams()->statisticsBySeason($seasonId);

最佳射手

通过赛季ID获取最佳射手

FootballApi::topscorers()->bySeason($seasonId);

通过阶段ID获取最佳射手

FootballApi::topscorers()->byStage($stageId);

转会

获取所有转会

FootballApi::transfers()->all();

通过ID获取转会

FootballApi::transfers()->find($transferId);

获取最近的转会

FootballApi::transfers()->latest();

通过两个日期获取转会

FootballApi::transfers()->byDateRange($from, $to);

通过队伍ID获取转会信息

FootballApi::transfers()->byTeam($teamId);

通过球员ID获取转会信息

FootballApi::transfers()->byPlayer($playerId);

电视频道

获取所有电视频道

FootballApi::tvStations()->all();

通过ID获取电视频道

FootballApi::tvStations()->find($tvStationId);

通过比赛 ID 获取电视频道

FootballApi::tvStations()->byFixture($fixtureId);

通过电视频道 ID 获取即将进行的比赛

FootballApi::tvStations($tvStationId)->upcomingFixtures();

通过电视频道 ID 获取过去的比赛

FootballApi::tvStations($tvStationId)->pastFixtures();

类型

获取所有类型

FootballApi::types()->all();

通过ID获取类型

FootballApi::types()->find($typeId);

通过实体获取类型

FootballApi::types()->byEntities();

场地

获取所有场地

FootballApi::venues()->all();

通过ID获取场地

FootballApi::venues()->find($venueId);

通过赛季ID获取场地

FootballApi::venues()->bySeason($seasonId);

通过名称搜索场地

FootballApi::venues()->search($name);