PHP code example of fezz / money-magic

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

    

fezz / money-magic example snippets


use Fezz\MoneyMagic\Concerns\HasMoneyAttributes;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use HasMoneyAttributes;

    protected array $money = [
        'price' => 'currency', // or null to use default currency-column
    ];
}

// Setting a price (stores as minor units)
$product->price = 12.99; // Stores 1299 in price_minor column

// Accessing the price
$product->price; // 12.99 (float)
$product->price_minor; // 1299 (int)
$product->price_money; // Brick\Money\Money instance
$product->price_formatted; // "€12,99" (formatted string)

// Working with Money object
$product->price_money->multiply(2); // Returns new Money instance
$product->price_money->getAmount(); // Decimal instance
bash
php artisan vendor:publish --tag="money-magic-config"