Download the PHP package mkeremcansev/laravel-commission without Composer
On this page you can find all versions of the php package mkeremcansev/laravel-commission. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mkeremcansev/laravel-commission
More information about mkeremcansev/laravel-commission
Files in mkeremcansev/laravel-commission
Package laravel-commission
Short Description A flexible package to calculate and log commissions in Laravel.
License MIT
Homepage https://github.com/mkeremcansev/laravel-commission
Informations about the package 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:
-
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.
-
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
, androunding
. -
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.
-
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.
- 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:
-
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
You can install the package via composer:
You can publish the migrations with:
You can run the migrations with:
You can publish the config file with:
Usage
-
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. -
Use the Trait: Use the
HasCommission
trait within your model to gain access to the commission calculation methods. -
Implement the Method: Implement the
getCommissionableColumns()
method in your model to specify which columns can have commissions applied. -
Calculate Commissions: Use the
calculate('price')
method to apply commissions to your model.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 value100
instead of theprice
column value. For example;
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
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:
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:
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.
-
Learn how to set an end date for a commission to prevent further calculations after that date.
-
Understand how the is_total column aggregates all applicable commission amounts for a more comprehensive total.
-
Discover how to apply a maximum amount limit for commission calculations based on specified criteria.
-
Explore how minimum amount checks are applied based on product price, ensuring that commissions are calculated only when the price meets the minimum criteria.
-
Find out how the rounding down method impacts commission calculations and ensures the amounts are adjusted downwards.
-
Learn how the rounding up method impacts commission calculations and ensures the amounts are adjusted upwards.
-
Discover how the commission status (true/false) affects whether a commission is included in calculations.
- Learn about the default commission calculation process and its importance in the overall commission framework.
Testing
Credits
- Mustafa Kerem CANSEV
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-commission with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0