PHPackages                             mkeremcansev/laravel-commission - 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. mkeremcansev/laravel-commission

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

mkeremcansev/laravel-commission
===============================

A flexible package to calculate and log commissions in Laravel.

1.0.4(1y ago)62211MITPHPPHP ^8.2

Since Oct 3Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mkeremcansev/laravel-commission)[ Packagist](https://packagist.org/packages/mkeremcansev/laravel-commission)[ Docs](https://github.com/mkeremcansev/laravel-commission)[ GitHub Sponsors](https://github.com/Mkeremcansev)[ RSS](/packages/mkeremcansev-laravel-commission/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (8)Versions (6)Used By (0)

   ![Package Image](https://camo.githubusercontent.com/abf343d9962a269bf642cd0c37f4a124144c0d57c28ae15711fdc90773d92289/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c253230436f6d6d697373696f6e2e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d6d6b6572656d63616e7365762532466c61726176656c2d636f6d6d697373696f6e267061747465726e3d617263686974656374267374796c653d7374796c655f31266465736372697074696f6e3d412b666c657869626c652b7061636b6167652b746f2b63616c63756c6174652b616e642b6c6f672b636f6d6d697373696f6e732b696e2b4c61726176656c2e266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d726563656970742d746178)What is Laravel Commission?
---------------------------

[](#what-is-laravel-commission)

Laravel Commission is a powerful package designed to simplify the management and calculation of commissions within Laravel applications. This package provides a flexible and extensible system for defining various types of commissions, whether they are based on percentages, fixed amounts, or more complex criteria.

### Key Features:

[](#key-features)

1. **Multiple Commission Types**: Laravel Commission allows you to define various commission types, such as percentage-based, fixed amount, or a combination of both. This flexibility enables developers to tailor commission structures to meet specific business requirements.
2. **Dynamic Calculation**: The package supports dynamic commission calculations based on the original product price or total price after applying other commissions. It accommodates different scenarios through the use of parameters such as `is_total`, `min_amount`, `max_amount`, and `rounding`.
3. **Comprehensive History Tracking**: Laravel Commission provides functionality to track the history of commission calculations, allowing businesses to maintain an accurate record of commissions applied over time.
4. **Integration with Eloquent Models**: The package seamlessly integrates with Laravel's Eloquent ORM, enabling developers to associate commissions with various models, such as products, orders, or services.
5. **Extensibility and Customization**: Developers can easily extend the functionality of the package to create custom commission logic that suits their business needs. This makes it easy to adapt to different use cases and scenarios.

### Use Cases:

[](#use-cases)

- **E-commerce Platforms**: Laravel Commission is particularly useful for e-commerce applications where various commission rates need to be applied based on different products, sales channels, or user roles.
- **Affiliate Programs**: Businesses can manage affiliate commissions efficiently, calculating payouts based on sales generated by affiliates with flexible commission structures.
- **Sales Teams**: Organizations can implement commission structures for sales representatives, rewarding them based on their performance and sales targets.

In summary, Laravel Commission is a versatile and robust solution for managing commissions in Laravel applications, providing developers with the tools they need to implement and customize commission calculations effectively. Whether you're building an e-commerce site, an affiliate platform, or a sales management system, this package can help streamline your commission management processes.

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

[](#installation)

You can install the package via composer:

```
composer require mkeremcansev/laravel-commission
```

You can publish the migrations with:

```
php artisan vendor:publish --tag="laravel-commission-migrations"
```

You can run the migrations with:

```
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="laravel-commission-config"
```

Usage
-----

[](#usage)

1. **Implement the Interface**: Ensure that the model you want to apply commissions to implements the `HasCommissionInterface`. This interface defines the methods required for commission calculations.
2. **Use the Trait**: Use the `HasCommission` trait within your model to gain access to the commission calculation methods.
3. **Implement the Method**: Implement the `getCommissionableColumns()` method in your model to specify which columns can have commissions applied.

    ```
    use Mkeremcansev\LaravelCommission\Contracts\HasCommissionInterface;
    use Mkeremcansev\LaravelCommission\Traits\HasCommission;

    class YourModel extends Model implements HasCommissionInterface
    {
        use HasCommission; // Use the HasCommission trait

        // Implement the required method from the HasCommissionInterface
        public function getCommissionableColumns(): array
        {
            return ['price', 'total']; // Example columns that can have commissions applied
        }
    }
    ```
4. **Calculate Commissions**: Use the `calculate('price')` method to apply commissions to your model.

    ```
    $model = YourModel::find(1);
    $calculatedCommission = $model->calculate('price');
    $calculatedCommission->totalCommissionAmount; // The total commission amount applied
    $calculatedCommission->totalIncludedPreviousCommissionAmount; // The total amount including previous commissions
    $calculatedCommission->totalAmount; // The total amount after commissions
    $calculatedCommission->originalAmount; // The original amount before commissions
    ```

    **Note**: If you want to calculate based on a custom value instead of using the column value, you can provide a second parameter to the calculate method. For example, `$model->calculate('price', 100)` will calculate the commission based on the value `100` instead of the `price` column value. For example;

    ```
    $model = YourModel::find(1);
    $calculatedCommission = $model->calculate('price', 100);
    $calculatedCommission->totalCommissionAmount; // The total commission amount applied
    $calculatedCommission->totalIncludedPreviousCommissionAmount; // The total amount including previous commissions
    $calculatedCommission->totalAmount; // The total amount after commissions
    $calculatedCommission->originalAmount; // The original amount before commissions
    ```

### Important Note

[](#important-note)

The `calculate()` method returns a `\Mkeremcansev\LaravelCommission\Services\Contexts\CommissionCalculationResultContext` or `array` or `null`.

**Null**: If the model `getCommissionableColumns()` method is return a empty array.

**Array**: If the model `getCommissionableColumns()` method has multiple columns. (Return array of `\Mkeremcansev\LaravelCommission\Services\Contexts\CommissionCalculationResultContext`)

**CommissionCalculationResultContext**: If the model `getCommissionableColumns()` method has only one column.

### Adding Custom Pipes After Commission Calculation

[](#adding-custom-pipes-after-commission-calculation)

#### 1. Creating a `CustomPipe` Class

[](#1-creating-a-custompipe-class)

Create a pipe class that will run after the commission calculation is done. Each `pipe` class receives the commission calculation context in the `handle` method, allowing you to further process the result. In this example, we use the `BaseCommissionCalculatorContext` class as a type hint for the context:

```
use Mkeremcansev\LaravelCommission\Services\Contexts\BaseCommissionCalculatorContext;

class CustomPipe
{
    public function handle(BaseCommissionCalculatorContext $context, Closure $next)
    {
        // Custom logic after the commission is calculated

        return $next($context);
    }
}
```

#### 2. Registering the `CustomPipe` Class

[](#2-registering-the-custompipe-class)

Add the `CustomPipe` class to the `commission.pipes` configuration array in the `config/commission.php` file. This configuration array defines the sequence of pipes that will be executed after the commission calculation:

```
'pipes' => [
    CustomPipe::class,
],
```

If you want a commission not to be calculated after a specific date, refer to the following documentation:
----------------------------------------------------------------------------------------------------------

[](#if-you-want-a-commission-not-to-be-calculated-after-a-specific-date-refer-to-the-following-documentation)

- **[Understand the process of defining a start date for a commission, which controls when the commission calculations begin.](docs/commission-with-start-date.md)**
- **[Learn how to set an end date for a commission to prevent further calculations after that date.](docs/commission-with-end-date.md)**
- **[Understand how the is\_total column aggregates all applicable commission amounts for a more comprehensive total.](docs/commission-with-is-total.md)**
- **[Discover how to apply a maximum amount limit for commission calculations based on specified criteria.](docs/commission-with-max-amount.md)**
- **[Explore how minimum amount checks are applied based on product price, ensuring that commissions are calculated only when the price meets the minimum criteria.](docs/commission-with-min-amount.md)**
- **[Find out how the rounding down method impacts commission calculations and ensures the amounts are adjusted downwards.](docs/commission-with-rounding-down.md)**
- **[Learn how the rounding up method impacts commission calculations and ensures the amounts are adjusted upwards.](docs/commission-with-rounding-up.md)**
- **[Discover how the commission status (true/false) affects whether a commission is included in calculations.](docs/commission-with-status.md)**
- **[Learn about the default commission calculation process and its importance in the overall commission framework.](docs/default-commission-calculation.md)**

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Mustafa Kerem CANSEV](https://github.com/mkeremcansev)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance41

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~4 days

Total

5

Last Release

567d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a29f15e6484cb5aea854e2efb6cbe532c480ca298c73673d1a1ee612ada65eee?d=identicon)[mkeremcansev](/maintainers/mkeremcansev)

---

Top Contributors

[![mkeremcansev](https://avatars.githubusercontent.com/u/76810832?v=4)](https://github.com/mkeremcansev "mkeremcansev (141 commits)")

---

Tags

laravelmkeremcansevlaravel-commission

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/mkeremcansev-laravel-commission/health.svg)

```
[![Health](https://phpackages.com/badges/mkeremcansev-laravel-commission/health.svg)](https://phpackages.com/packages/mkeremcansev-laravel-commission)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

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

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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