PHP code example of mkeremcansev / laravel-commission

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

    

mkeremcansev / laravel-commission example snippets


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

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

       // Implement the 

   $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
   

    $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
    

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);
    }
}

'pipes' => [
    CustomPipe::class,
],
bash
php artisan vendor:publish --tag="laravel-commission-migrations"
bash
php artisan migrate
bash
php artisan vendor:publish --tag="laravel-commission-config"