1. Go to this page and download the library: Download aichadigital/lara100 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/ */
// In your database: 1999 (integer - cents)
// In your application: 19.99 (decimal - dollars/euros)
use AichaDigital\Lara100\Casts\Base100;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
protected function casts(): array
{
return [
'price' => Base100::class,
'cost' => Base100::class,
'tax' => Base100::class,
];
}
}
$product = new Product;
$product->price = 19.99; // You set: 19.99 (decimal)
$product->save(); // DB stores: 1999 (integer cents)
echo $product->price; // You get: 19.99 (decimal)
// Arithmetic operations work perfectly with decimals
$total = $product->price + $product->tax; // 19.99 + 2.50 = 22.49 ✅
use AichaDigital\Lara100\Concerns\HasBase100;
use Illuminate\Database\Eloquent\Model;
class Product extends Model
{
use HasBase100;
protected function base100Attributes(): array
{
return ['price', 'cost', 'tax', 'discount'];
}
}
// Zero values
$product->price = 0.00; // Stores 0 in DB
// Negative values (refunds, discounts)
$refund->amount = -25.00; // Stores -2500 in DB (negative cents)
// Large numbers
$property->price = 500000.00; // Stores 50000000 in DB ($500,000.00)