PHP code example of alexoid / laravel-garmin

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

    

alexoid / laravel-garmin example snippets


use Alexoid\GarminConnect\GarminConnect;

// Login with credentials
$garmin = new GarminConnect(
    email: '[email protected]',
    password: 'yourpassword',
);
$garmin->login('~/.garminconnect');

// Subsequent runs — tokens are reused automatically
$garmin = new GarminConnect();
$garmin->login('~/.garminconnect');

// Get data
$summary = $garmin->getUserSummary('2026-03-02');
echo "Steps: " . $summary['totalSteps'];

$hr = $garmin->getHeartRates('2026-03-02');
echo "Resting HR: " . $hr['restingHeartRate'];

$activities = $garmin->getActivities(0, 10);

$garmin = new GarminConnect(
    email: '[email protected]',
    password: 'yourpassword',
    returnOnMfa: true,
);

[$status, $clientState] = $garmin->login();

if ($status === 'needs_mfa') {
    $mfaCode = readline('MFA code: '); // or get from your UI
    $garmin->resumeLogin($clientState, $mfaCode, '~/.garminconnect');
}

// Now authenticated
$summary = $garmin->getUserSummary(date('Y-m-d'));

use Alexoid\GarminConnect\Auth\MfaHandler;

class CliMfaHandler implements MfaHandler
{
    public function promptMfaCode(): string
    {
        echo "Enter MFA code: ";
        return trim(fgets(STDIN));
    }
}

$garmin = new GarminConnect(
    email: '[email protected]',
    password: 'yourpassword',
    mfaHandler: new CliMfaHandler(),
);
$garmin->login('~/.garminconnect');

use Alexoid\GarminConnect\Laravel\GarminConnect;

GarminConnect::login();

$stats = GarminConnect::getUserSummary(now()->format('Y-m-d'));
$hr = GarminConnect::getHeartRates(now()->format('Y-m-d'));
bash
php artisan vendor:publish --tag=garminconnect-config
bash
php artisan garmin:login