PHPackages                             longestdrive/laravel-golf-handicap-calculator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. longestdrive/laravel-golf-handicap-calculator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

longestdrive/laravel-golf-handicap-calculator
=============================================

calculates golf handicaps using various methods including WHS rules

2.0.1(3mo ago)087[4 PRs](https://github.com/longestdrive/laravel-golf-handicap-calculator/pulls)MITPHPPHP ^8.3CI passing

Since Aug 8Pushed 2mo agoCompare

[ Source](https://github.com/longestdrive/laravel-golf-handicap-calculator)[ Packagist](https://packagist.org/packages/longestdrive/laravel-golf-handicap-calculator)[ Docs](https://github.com/longestdrive/laravel-golf-handicap-calculator)[ GitHub Sponsors](https://github.com/Longestdrive)[ RSS](/packages/longestdrive-laravel-golf-handicap-calculator/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (5)Dependencies (30)Versions (12)Used By (0)

calculates golf handicaps using various methods including WHS rules
===================================================================

[](#calculates-golf-handicaps-using-various-methods-including-whs-rules)

[![Latest Version on Packagist](https://camo.githubusercontent.com/03ce2b07edcf10dcdc8e217b7b3aeb858ed840a167ea0437cbe8be349e9efed1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6f6e6765737464726976652f6c61726176656c2d676f6c662d68616e64696361702d63616c63756c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/longestdrive/laravel-golf-handicap-calculator)[![GitHub Tests Action Status](https://camo.githubusercontent.com/2925129ca15fd100bcb8036ae631c29fb9a8d7d5ae33ce155df242d5ca2e1c81/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6f6e6765737464726976652f6c61726176656c2d676f6c662d68616e64696361702d63616c63756c61746f722f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/longestdrive/laravel-golf-handicap-calculator/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/e1617e051efed69696023f14537c7c420eaa545eb692e29657a4b556863f4404/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c6f6e6765737464726976652f6c61726176656c2d676f6c662d68616e64696361702d63616c63756c61746f722f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/longestdrive/laravel-golf-handicap-calculator/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/ecf709f4ebfd3ed2c31246e7902b69f151735a30f74ddb02d181efe95cc9aa5e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c6f6e6765737464726976652f6c61726176656c2d676f6c662d68616e64696361702d63616c63756c61746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/longestdrive/laravel-golf-handicap-calculator)

A Laravel package for calculating golf handicaps using various methods, including the World Handicap System (WHS) rules. This package provides a flexible factory-based approach that allows you to:

- Use the built-in WHS handicap calculator
- Register and use the included SimpleHandicapCalculator
- Create and register your own custom handicap calculators
- Switch between different calculation methods at runtime

The package uses a factory pattern that makes it easy to extend with your own calculation methods while maintaining a consistent interface.

Support us
----------

[](#support-us)

Built using \[spatie/laravel-package-skeleton\]

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require longestdrive/laravel-golf-handicap-calculator
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-golf-handicap-calculator-config"
```

WIP This is the contents of the published config file:

```
return [
];
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

#### Using the Factory Approach (Recommended)

[](#using-the-factory-approach-recommended)

```
use Longestdrive\LaravelGolfHandicapCalculator\Facades\GolfHandicapCalculator;

// Create a calculator instance using the factory (uses WHSHandicapCalculator by default)
$calculator = GolfHandicapCalculator::make('whs');

// Calculate a handicap using the options array
$handicap = $calculator->getHandicap([
    'actualHandicap' => 15.4,  // Player's actual handicap (float)
    'courseSlope' => 125,      // Course slope rating (int)
    'courseRating' => 72.1,    // Course rating (float)
    'coursePar' => 72          // Course par (int)
]);

echo "Playing Handicap: " . $handicap;
```

#### Legacy Approach

[](#legacy-approach)

```
use Longestdrive\LaravelGolfHandicapCalculator\LaravelGolfHandicapCalculator;

// Create a calculator instance (uses WHSHandicapCalculator by default)
$calculator = new LaravelGolfHandicapCalculator();

// Calculate a handicap using the options array
$handicap = $calculator->getHandicap([
    'actualHandicap' => 15.4,  // Player's actual handicap (float)
    'courseSlope' => 125,      // Course slope rating (int)
    'courseRating' => 72.1,    // Course rating (float)
    'coursePar' => 72          // Course par (int)
]);

echo "Playing Handicap: " . $handicap;
```

### Reverse Calculating a Handicap Index

[](#reverse-calculating-a-handicap-index)

Every calculator also supports `reverseHandicapIndex()`, which works backwards from a known playing handicap to estimate the original handicap index. This is useful when you have a course handicap and want to derive the underlying handicap index.

> **Note:** Because the playing handicap is a rounded integer, the reverse result is an approximation — not a guaranteed exact match of the original handicap index.

```
use Longestdrive\LaravelGolfHandicapCalculator\Facades\GolfHandicapCalculator;

$calculator = GolfHandicapCalculator::make('whs');

$handicapIndex = $calculator->reverseHandicapIndex([
    'playingHandicap' => 8,   // Known playing/course handicap (int)
    'courseSlope'     => 128, // Course slope rating (int|float)
    'courseRating'    => 70.3, // Course rating (float|int)
    'coursePar'       => 72,  // Course par (int)
]);

// Returns a float (or null if courseSlope is zero)
echo "Estimated Handicap Index: " . $handicapIndex; // e.g. 8.563
```

The method returns `null` if `courseSlope` is zero (to avoid division by zero).

#### WHS reverse formula

[](#whs-reverse-formula)

```
handicapIndex = (playingHandicap - (courseRating - coursePar)) × (113 / courseSlope)

```

#### Simple reverse formula

[](#simple-reverse-formula)

```
handicapIndex = (playingHandicap - (courseRating - coursePar) / 2) × (100 / courseSlope)

```

### Using Different Calculation Methods

[](#using-different-calculation-methods)

The package is designed with a flexible factory approach that allows you to implement and use different handicap calculation strategies:

#### Using the Factory Approach (Recommended)

[](#using-the-factory-approach-recommended-1)

```
use Longestdrive\LaravelGolfHandicapCalculator\Facades\GolfHandicapCalculator;
use App\Services\CustomHandicapCalculator; // Your custom implementation

// Register your custom calculator
GolfHandicapCalculator::register('custom', CustomHandicapCalculator::class);

// Create a calculator instance using the factory
$whsCalculator = GolfHandicapCalculator::make('whs'); // Default WHS calculator
$customCalculator = GolfHandicapCalculator::make('custom'); // Your custom calculator

// Calculate handicap using the selected calculator
$options = [
    'actualHandicap' => 15.4,
    'courseSlope' => 125,
    'courseRating' => 72.1,
    'coursePar' => 72
];

$handicap = $whsCalculator->getHandicap($options);
$customHandicap = $customCalculator->getHandicap($options);
```

#### Available Default Calculators

[](#available-default-calculators)

The package comes with the following built-in calculator:

1. `whs` - World Handicap System calculator (default)

The package also includes a `SimpleHandicapCalculator` class that you can register manually:

```
use Longestdrive\LaravelGolfHandicapCalculator\Facades\GolfHandicapCalculator;
use Longestdrive\LaravelGolfHandicapCalculator\Calculator\SimpleHandicapCalculator;

// Register the SimpleHandicapCalculator
GolfHandicapCalculator::register('simple', SimpleHandicapCalculator::class);

// Now you can use it
$simpleCalculator = GolfHandicapCalculator::make('simple');
$handicap = $simpleCalculator->getHandicap($options);
```

#### Legacy Approach

[](#legacy-approach-1)

You can also use the direct instantiation approach:

```
use Longestdrive\LaravelGolfHandicapCalculator\LaravelGolfHandicapCalculator;
use Longestdrive\LaravelGolfHandicapCalculator\Calculator\WHSHandicapCalculator;
use App\Services\CustomHandicapCalculator; // Your custom implementation

// Using the default WHS calculator
$calculator = new LaravelGolfHandicapCalculator();

// Explicitly using the WHS calculator
$calculator = new LaravelGolfHandicapCalculator(new WHSHandicapCalculator());

// Using your custom calculator
$calculator = new LaravelGolfHandicapCalculator(new CustomHandicapCalculator());

// Switching calculators at runtime
$calculator = new LaravelGolfHandicapCalculator();
$calculator->setCalculator(new CustomHandicapCalculator());

// All calculators use the same options array format
$options = [
    'actualHandicap' => 15.4,
    'courseSlope' => 125,
    'courseRating' => 72.1,
    'coursePar' => 72
];

$handicap = $calculator->getHandicap($options);
```

### Creating Your Own Calculator

[](#creating-your-own-calculator)

You can create your own handicap calculator by implementing the `HandicapCalculatorInterface` and registering it with the factory:

#### 1. Create Your Calculator Class

[](#1-create-your-calculator-class)

```
use Longestdrive\LaravelGolfHandicapCalculator\Calculator\HandicapCalculatorInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class CustomHandicapCalculator implements HandicapCalculatorInterface
{
    private array $options;

    public function getHandicap(array $options): int
    {
        $this->setCalculationOptions($options);

        // Your custom calculation logic here
        return (int) round(/* your formula using $this->options */);
    }

    public function reverseHandicapIndex(array $options): ?float
    {
        $this->setReverseCalculationOptions($options);

        if ($this->options['courseSlope'] == 0) {
            return null;
        }

        // Your custom reverse formula here
        return /* derived handicap index as float */;
    }

    private function setCalculationOptions(array $options): void
    {
        $resolver = new OptionsResolver();

        $resolver->setRequired([
            'actualHandicap',
            'courseSlope',
            'courseRating',
            'coursePar',
        ]);

        $resolver->setAllowedTypes('actualHandicap', ['float', 'int']);
        $resolver->setAllowedTypes('courseSlope', ['float', 'int']);
        $resolver->setAllowedTypes('courseRating', ['float', 'int']);
        $resolver->setAllowedTypes('coursePar', 'int');

        $this->options = $resolver->resolve($options);
    }

    private function setReverseCalculationOptions(array $options): void
    {
        $resolver = new OptionsResolver();

        $resolver->setRequired([
            'playingHandicap',
            'courseSlope',
            'courseRating',
            'coursePar',
        ]);

        $resolver->setAllowedTypes('playingHandicap', 'int');
        $resolver->setAllowedTypes('courseSlope', ['float', 'int']);
        $resolver->setAllowedTypes('courseRating', ['float', 'int']);
        $resolver->setAllowedTypes('coursePar', 'int');

        $this->options = $resolver->resolve($options);
    }
}
```

#### 2. Register Your Calculator with the Factory

[](#2-register-your-calculator-with-the-factory)

You can register your calculator in a service provider:

```
use Longestdrive\LaravelGolfHandicapCalculator\Facades\GolfHandicapCalculator;
use App\Services\CustomHandicapCalculator;

public function boot()
{
    // Register your custom calculator
    GolfHandicapCalculator::register('custom', CustomHandicapCalculator::class);
}
```

Or register it directly in your application code:

```
use Longestdrive\LaravelGolfHandicapCalculator\Facades\GolfHandicapCalculator;
use App\Services\CustomHandicapCalculator;

// Register your custom calculator
GolfHandicapCalculator::register('custom', CustomHandicapCalculator::class);
```

#### 3. Use Your Custom Calculator

[](#3-use-your-custom-calculator)

```
use Longestdrive\LaravelGolfHandicapCalculator\Facades\GolfHandicapCalculator;

// Create an instance of your custom calculator
$calculator = GolfHandicapCalculator::make('custom');

// Use it to calculate a handicap
$handicap = $calculator->getHandicap([
    'actualHandicap' => 15.4,
    'courseSlope' => 125,
    'courseRating' => 72.1,
    'coursePar' => 72
]);
```

### Laravel Service Container Integration

[](#laravel-service-container-integration)

The package registers the HandicapCalculatorFactory in Laravel's service container, allowing you to use dependency injection:

#### Using the Factory in Controllers

[](#using-the-factory-in-controllers)

```
use Longestdrive\LaravelGolfHandicapCalculator\Calculator\HandicapCalculatorFactory;
use Illuminate\Http\Request;

class GolfController extends Controller
{
    protected $calculatorFactory;

    public function __construct(HandicapCalculatorFactory $calculatorFactory)
    {
        $this->calculatorFactory = $calculatorFactory;
    }

    public function calculateHandicap(Request $request, string $calculatorType = 'whs')
    {
        // Get the requested calculator type or default to 'whs'
        $calculator = $this->calculatorFactory->make($calculatorType);

        // Create options array from request inputs
        $options = [
            'actualHandicap' => (float) $request->input('actual_handicap'),
            'courseSlope' => (int) $request->input('course_slope'),
            'courseRating' => (float) $request->input('course_rating'),
            'coursePar' => (int) $request->input('course_par')
        ];

        // Pass the options array to the calculator
        $handicap = $calculator->getHandicap($options);

        return response()->json(['handicap' => $handicap]);
    }
}
```

#### Using the Facade in Controllers

[](#using-the-facade-in-controllers)

```
use Longestdrive\LaravelGolfHandicapCalculator\Facades\GolfHandicapCalculator;
use Illuminate\Http\Request;

class GolfController extends Controller
{
    public function calculateHandicap(Request $request, string $calculatorType = 'whs')
    {
        // Get the requested calculator type or default to 'whs'
        $calculator = GolfHandicapCalculator::make($calculatorType);

        // Create options array from request inputs
        $options = [
            'actualHandicap' => (float) $request->input('actual_handicap'),
            'courseSlope' => (int) $request->input('course_slope'),
            'courseRating' => (float) $request->input('course_rating'),
            'coursePar' => (int) $request->input('course_par')
        ];

        // Pass the options array to the calculator
        $handicap = $calculator->getHandicap($options);

        return response()->json(['handicap' => $handicap]);
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Longestdrive](https://github.com/Longestdrive)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~57 days

Total

5

Last Release

93d ago

Major Versions

1.0.3 → 2.0.02026-03-25

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3138181?v=4)[longestdrive](/maintainers/longestdrive)[@longestdrive](https://github.com/longestdrive)

---

Top Contributors

[![longestdrive](https://avatars.githubusercontent.com/u/3138181?v=4)](https://github.com/longestdrive "longestdrive (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (1 commits)")

---

Tags

laravelLongestdrivelaravel-golf-handicap-calculator

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/longestdrive-laravel-golf-handicap-calculator/health.svg)

```
[![Health](https://phpackages.com/badges/longestdrive-laravel-golf-handicap-calculator/health.svg)](https://phpackages.com/packages/longestdrive-laravel-golf-handicap-calculator)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.3M42](/packages/spatie-laravel-pdf)[codewithdennis/filament-select-tree

The multi-level select field enables you to make single selections from a predefined list of options that are organized into multiple levels or depths.

328482.0k25](/packages/codewithdennis-filament-select-tree)[nativephp/desktop

NativePHP for Desktop

38133.6k8](/packages/nativephp-desktop)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

124581.3k](/packages/worksome-exchange)[rawilk/profile-filament-plugin

Profile &amp; MFA starter kit for filament.

3913.7k](/packages/rawilk-profile-filament-plugin)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

63105.4k2](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
