zacksmash/mlb-stats is a Laravel package for access the mlb stats api.
It currently has 5 GitHub stars and 8 downloads on Packagist (latest version v0.0.1).
Install it with composer require zacksmash/mlb-stats.
Discover more Laravel packages by zacksmash
or browse all Laravel packages to compare alternatives.
Last updated
A comprehensive PHP client for the MLB Stats API that provides easy access to baseball statistics, game data, team information, player stats, and more. This package offers a clean, fluent interface with full parameter validation, enum support, and Laravel integration.
Key Features:
$response = MlbStats::gameLIveFeed($gamePk)->get();
// Get the most recent play
$response->data->deepGet('liveData.plays.allPlays.{last}');
You can install the package via composer:
composer require zacksmash/mlb-stats
If you're using Laravel, the package will be auto-discovered. You can optionally publish the configuration file:
php artisan vendor:publish --tag="mlb-stats-config"
This package provides a simple and elegant way to access the MLB Stats API. You can use either the Facade or the underlying service class directly.
use Zacksmash\MlbStats\Facades\MlbStats;
// Get all MLB teams
$teams = MlbStats::teams()->get();
// Get San Francisco Giants team information
$giants = MlbStats::team(137) // San Francisco Giants
->get();
// Get Giants schedule for July 4th weekend
$schedule = MlbStats::schedule()
->sportId(1) // MLB
->teamId(137) // Giants
->startDate('2025-07-03')
->endDate('2025-07-05')
->get();
// Get Giants player information
$busterPosey = MlbStats::person(457763) // Buster Posey
->get();
The API provides various configuration endpoints that return reference data:
use Zacksmash\MlbStats\Facades\MlbStats;
// Get all available positions
$positions = MlbStats::positions()->get();
// Get all game types and statuses
$gameTypes = MlbStats::gameTypes()->get();
$gameStatuses = MlbStats::gameStatuses()->get();
// Get all stat types with descriptions
$statTypes = MlbStats::statTypes()->get();
$statGroups = MlbStats::statGroups()->get();
// Get available awards and achievement statuses
$awards = MlbStats::awards()->get();
$achievements = MlbStats::achievementStatuses()->get();
// Get venue information for Oracle Park (Giants home stadium)
$oraclePark = MlbStats::venue(2395) // Oracle Park
->get();
// Get all MLB venues
$venues = MlbStats::venues()->get();
$statTypes = MlbStats::statTypes()->get();
// Get available awards
$awards = MlbStats::awards()->get();
// Get Giants team stats for the 2024 season
$giantsStats = MlbStats::teamStats(137) // Giants
->season(2024)
->statGroup('hitting')
->group('hitting')
->stats('season')
->get();
// Get league-wide stat leaders (find where Giants players rank)
$statLeaders = MlbStats::statsLeaders()
->leaderCategories(['homeRuns', 'strikeouts'])
->season(2024)
->leagueId(104) // National League
->limit(10)
->get();
// Get Giants team history and affiliates
$giantsHistory = MlbStats::teamHistory(137)->get();
$giantsAffiliates = MlbStats::teamAffiliates(137)->get();
// Get teams stats comparison across the league
$allTeamsStats = MlbStats::teamsStats()
->season(2024)
->statGroup('hitting')
->get();
// Get Giants current roster
$giantsRoster = MlbStats::teamRoster(137) // Giants
->rosterType('active')
->season(2024)
->get();
// Get specific Giants players
$mattChapman = MlbStats::person(656305) // Matt Chapman (3B)
->get();
$loganWebb = MlbStats::person(657277) // Logan Webb (P)
->get();
// Get player stats for a specific game
$playerGameStats = MlbStats::playerGameStats(656305, 745927) // Chapman in specific game
->get();
// Get Giants coaching staff
$giantsCoaches = MlbStats::teamCoaches(137)
->season(2024)
->get();
// Get Giants personnel (front office, etc.)
$giantsPersonnel = MlbStats::teamPersonnel(137)->get();
// Search for players by name
$playerSearch = MlbStats::peopleSearch()
->names(['Logan Webb'])
->get();
// Get free agents who might join the Giants
$freeAgents = MlbStats::playerFreeAgents()
->season(2024)
->get();
// Get Giants live game feed (example game)
$liveFeed = MlbStats::gameLiveFeed(745927) // Giants vs Dodgers
->get();
// Get detailed game play-by-play
$playByPlay = MlbStats::gamePlayByPlay(745927)->get();
// Get game boxscore with detailed stats
$boxscore = MlbStats::gameBoxscore(745927)
->timecode('20240701_150000')
->fields('teams,players')
->get();
// Get game content (highlights, recap, etc.)
$gameContent = MlbStats::gameContent(745927)
->highlightLimit(10)
->get();
// Get game context metrics and analytics
$gameMetrics = MlbStats::gameContextMetrics(745927)->get();
$winProbability = MlbStats::gameWinProbability(745927)->get();
// Get weather information for Oracle Park games
$weatherForecast = MlbStats::weatherForecast(745927, 'open')
->get();
// Get Giants schedule for the season
$giantsSchedule = MlbStats::schedule()
->teamId(137)
->season(2024)
->scheduleType('regularSeason')
->get();
// Get postseason schedule if Giants make playoffs
$postseason = MlbStats::schedulePostseason()
->season(2024)
->teamId(137)
->get();
use Zacksmash\MlbStats\Facades\MlbStats;
use Zacksmash\MlbStats\Enums\Position;
use Zacksmash\MlbStats\Enums\StatGroups;
// Get advanced hitting stats for Giants players
$giantsHittingStats = MlbStats::stats()
->stats('season')
->group(StatGroups::HITTING)
->teamId(137) // Giants
->season(2024)
->get();
// Get pitching stats for Giants rotation
$giantsPitchingStats = MlbStats::stats()
->stats('season')
->group(StatGroups::PITCHING)
->teamId(137)
->season(2024)
->get();
// Get stats for specific position (Giants catchers)
$giantsCatchers = MlbStats::stats()
->stats('season')
->group('hitting')
->position(Position::CATCHER)
->teamId(137)
->season(2024)
->get();
// Search for specific statistical achievements
$giantsSearch = MlbStats::statsSearch()
->group('hitting')
->season(2024)
->teamId(137)
->get();
// Get high/low stats across the league
$seasonHighs = MlbStats::highLow('season')
->sortStat('homeRuns')
->season(2024)
->get();
// Get milestone achievements
$milestones = MlbStats::milestones()
->fields(['milestones'])
->get();
use Zacksmash\MlbStats\Facades\MlbStats;
use Zacksmash\MlbStats\Exceptions\RequestFailedException;
use Zacksmash\MlbStats\Exceptions\InvalidParameterException;
try {
$giantsStats = MlbStats::teamStats(137) // Giants
->season(2024)
->statGroup('hitting')
->get();
} catch (InvalidParameterException $e) {
// Handle missing required parameters
echo "Missing required parameter: " . $e->getMessage();
} catch (RequestFailedException $e) {
// Handle API request failures
echo "API request failed: " . $e->getMessage();
}
Some endpoints in the MLB Stats API may return errors or have restricted access. The package includes documentation for these known issues:
These methods require special authorization that may not be publicly available:
batTrackingByPlay() - Bat tracking data for specific playsgameAnalytics() - Advanced game analyticsgameAnalyticsGuids() - Game analytics GUIDsgameGuidAnalytics() - GUID-specific analyticsgameGuidContextMetrics() - GUID context metricsgameGuidContextMetricsAverages() - GUID context metric averagesgameLastPitch() - Last pitch datagamePlayBiomechanics() - Play biomechanics datagamePlaySkeletalChunked() - Skeletal tracking data (chunked)gamePlaySkeletalFiles() - Skeletal tracking filesgameGuids() - Game GUID datajobsUmpireSchedule() - Umpire schedule informationpersonStatsMetrics() - Person statistics metricspropsPredictions() - Props predictionspropsPredictionsAdjust() - Adjusted props predictionsscheduleTrackingEvents() - Schedule tracking eventsstatsMetrics() - Advanced statistics metricsstatsOutsAboveAverage() - Outs above average statsstatsSearchBeast() - Advanced stats searchstatsSprayChart() - Spray chart datastatsStolenBaseProbability() - Stolen base probabilitystreaks() - Player/team streaksweatherBasic() - Basic weather dataweatherByPlay() - Play-specific weatherweatherForecast() - Weather forecastsweatherFull() - Full weather dataThese endpoints may not be currently available:
gameColorFeed() - Game color feed datagameColorFeedTimestamps() - Color feed timestampsThese endpoints may have server-side issues:
homeRunDerby() - Home Run Derby datahomeRunDerbyBracket() - Home Run Derby brackethomeRunDerbyMixed() - Mixed Home Run Derby datahomeRunDerbyPool() - Home Run Derby pool dataleaguesAllStarBallot() - All-Star ballot (leagues endpoint)personAward() - Person award informationreviews() - Game reviews dataThese endpoints may return empty results or object not found errors:
teamLeaders() - Team statistical leadersteamStats() - Team statistics (some configurations)Note: These limitations are based on the current state of the MLB Stats API and may change over time. Some methods may work with specific parameters or during certain periods (e.g., Home Run Derby methods during All-Star week).
composer test
Please see CHANGELOG for more information on what has changed recently.
DBAA, PR's Accepted!
Read more about the API docs here!
The MIT License (MIT). Please see License File for more information.
This package and its author are not affiliated with MLB or any MLB team. This API wrapper interfaces with MLB's Stats API. Use of MLB data is subject to the notice posted at http://gdx.mlb.com/components/copyright.txt.