PHP code example of freshleafmedia / laravel-money-cast
1. Go to this page and download the library: Download freshleafmedia/laravel-money-cast 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/ */
freshleafmedia / laravel-money-cast example snippets
use Freshleafmedia\MoneyCast\MoneyCast;
use Illuminate\Database\Eloquent\Model;
class MyModel extends Model
{
// ...
protected $casts = [
'cost' => MoneyCast::class,
];
// ...
}
$model = new MyModel();
$model->cost = new \Money\Money('100', new \Money\Currency('GBP'));
$model->save(); // 'GBP100' is persisted to the database.
$cost = MyModel::first()->cost; // Money\Money
$cost->getAmount() // '100'
$cost->getCurrency()->getCode() // 'GBP'