PHP code example of moirei / laravel-pricing

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

    

moirei / laravel-pricing example snippets


...
$product = Product::find(1);

$product->pricing([
    'model' => 'volume',
    'tiers' => [
      [
        'max' => 5,
        'unit_amount' => 3.6,
      ],
      [
        'max' => 10,
        'unit_amount' => 3.3,
      ],
      [
        'max' => 'infinity', // or `-1`
        'unit_amount' => 3.1,
        'flat_amount' => 1.2,
      ],
    ]
  ],
]);

$price = $product->price; // price for 1 item

$price = $product->price(4); // price = 4 x 3.6 = 14.4
$price = $product->price(7); // price = 7 x 3.3 = 23.1
$price = $product->price(15); // price = (15 x 3.1) + 1.2 = 47.7

composer run test