Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (16) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2020-11-06 (1 month ago) | Not yet rated by the users | Total: 21 This week: 1 | All time: 10,109 This week: 208 |
Version | License | PHP version | Categories | |||
laravel-money 1.0 | MIT/X Consortium ... | 5 | PHP 5, Libraries, Finances, Design Pa... |
Description | Author | |||
This package can manipulate model attribute as money values. Innovation Award
|
|
<p align="center"><a href="https://pharaonic.io" target="_blank"><img src="https://raw.githubusercontent.com/Pharaonic/logos/main/money.jpg" width="470"></a></p>
<p align="center"> <a href="https://github.com/Pharaonic/laravel-money" target="_blank"><img src="http://img.shields.io/badge/source-pharaonic/laravel--money-blue.svg?style=flat-square" alt="Source"></a> <a href="https://packagist.org/packages/pharaonic/laravel-money" target="_blank"><img src="https://img.shields.io/packagist/v/pharaonic/laravel-money?style=flat-square" alt="Packagist Version"></a><br> <a href="https://laravel.com" target="_blank"><img src="https://img.shields.io/badge/Laravel->=6.0-red.svg?style=flat-square" alt="Laravel"></a> <img src="https://img.shields.io/packagist/dt/pharaonic/laravel-money?style=flat-square" alt="Packagist Downloads"> <img src="http://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square" alt="Source"> </p>
Install the latest version using Composer:
$ composer require pharaonic/laravel-money
then publish the migration & config files
$ php artisan vendor:publish --tag=laravel-money
<a name="config"></a>
// config/Pharaonic/money.php
return [
// Default Language
'language' => 'en',
// Default Currency
'currency' => 'USD',
// Select specific currencies
'only' => [],
// Except specific currencies
'except' => [],
// Default fields names
'fields' => ['price']
];
<a name="options"></a>
use Pharaonic\Laravel\Money\Facades\Money;
// Setting default currency
Money::setCurrency('USD');
// Setting default language
// Supported language [ar, en, fr, de, es]
Money::setLanguage('ar');
// Select specific currencies
Money::only(['USD']);
// Except specific currencies
Money::except(['USD']);
// Get current language
$language = Money::getLanguage();
// Get currency Code, Name, Symbol
$currency_code = Money::getCurrencyCode();
$currency_name = Money::getCurrencyName();
$currency_symbol = Money::getCurrencySymbol();
// Get currencies list (code => name)
$currencies = Money::getCurrenciesList();
<a name="include"></a>
...
use Pharaonic\Laravel\Helpers\Traits\HasCustomAttributes;
use Pharaonic\Laravel\Money\HasMoney;
class Person extends Model
{
use HasCustomAttributes, HasMoney;
// You can include your all monies names here.
protected $moneyAttributes = ['balance'];
...
}
<a name="set"></a>
// Setting money to exists person
$person = Person::find(1);
$person->money('balance', 'USD', 100);
// Setting money to new person with current currency ($currency_code)
$person = Person::create([
'balance'
...
]);
<a name="get"></a>
$person = Person::find(1);
// Get money with specific currency
echo $person->money('balance', 'USD');
echo $person->balance; // 100.00
echo $person->balance->amount; // 100
echo $person->balance->withName(); // 100.00 USD
echo $person->balance->withSymbol(); // $ 100.00
echo $person->balance->toString() // one hundred dollars {PHP Extension intl}
<a name="actions"></a>
$person = Person::find(1);
$person->balance->withdraw(0.50); // withdraw 50 cents
$person->balance->deposit(10.50); // deposit 10 dollars and 50 cents
$person->balance->reset(); // resetting money to zero
<a name="relations_scopes"></a>
// Getting monies with all currencies
$monies = $person->monies;
// Getting all People who has no monies
dd(Person::withoutMonies()->get());
// with Currency only
$pplWithMoney = Person::withMoney('USD')->get();
// with Currency and name
$pplWithMoney = Person::withMoney('USD', 'balance')->get();
// with Currencies only
$pplWithMoney = Person::withAnyMoney(['USD'])->get();
// with Currencies and names
$pplWithMoney = Person::withAnyMoney(['USD'], ['balance'])->get();
<a name="aggregates"></a>
// Getting MIN Money
echo Person::minMoney('balance');
echo Person::minMoney('balance', 'USD');
// Getting MAX Money
echo Person::maxMoney('balance');
echo Person::maxMoney('balance', 'USD');
// Getting SUM All Monies
echo Person::sumMoney('balance');
echo Person::sumMoney('balance', 'USD');
// Getting SUM Negative Monies
echo Person::sumNegativeMoney('balance');
echo Person::sumNegativeMoney('balance', 'USD');
// Getting SUM Positive Monies
echo Person::sumPositiveMoney('balance');
echo Person::sumPositiveMoney('balance', 'USD');
// Getting Average Monies
echo Person::avgMoney('balance');
echo Person::avgMoney('balance', 'USD');
// Getting Count OF Monies Rows
echo Person::countMoney();
echo Person::countMoney('balance');
echo Person::countMoney(null, 'USD');
echo Person::countMoney('balance', 'USD');
<a name="events"></a>
...
class Person extends Model
{
...
/
* Setted Money with (Create/New/money method) Event
*
* @param string $name
* @param string $currency
* @param float $amount
* @return void
*/
public function setted(string $name, string $currency, float $amount)
{
//
}
/
* Withdrew Money Event
*
* @param string $name
* @param string $currency
* @param float $amount
* @return void
*/
public function withdrew(string $name, string $currency, float $amount)
{
//
}
/
* Deposited Money Event
*
* @param string $name
* @param string $currency
* @param float $amount
* @return void
*/
public function deposited(string $name, string $currency, float $amount)
{
//
}
/
* Reset Money Event
*
* @param string $name
* @param string $currency
* @return void
*/
public function reset(string $name, string $currency)
{
//
}
...
}
Files |
File | Role | Description | ||
---|---|---|---|---|
src (2 files, 5 directories) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
config (1 file) | ||||
data (2 files, 1 directory) | ||||
database (1 directory) | ||||
Facades (1 file) | ||||
Models (1 file) | ||||
HasMoney.php | Class | Class source | ||
MoneyServiceProvider.php | Class | Class source |
Files | / | src | / | data |
File | Role | Description | ||
---|---|---|---|---|
lang (5 files) | ||||
and.php | Aux. | Auxiliary script | ||
currencies.php | Aux. | Auxiliary script |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.