laravel-money | Currency formatting and conversion package for Laravel
kandi X-RAY | laravel-money Summary
kandi X-RAY | laravel-money Summary
Currency formatting and conversion package for Laravel
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Parse amount from string
- Register the package services .
- Allocate the money according to a list of ratios .
- Adds an amount to this object
- Parse an amount .
- Returns an array representation of this object .
- Get the currencies .
- Returns the symbol .
- Get the suffix
- Register money .
laravel-money Key Features
laravel-money Examples and Code Snippets
Community Discussions
Trending Discussions on laravel-money
QUESTION
I want to use the cknow/laravel-money
package in pretty much every page in my app. I thought a tidy way to do this would be to import the class in the parent blade. However, child templates do not seem to have access to the imported class.
I've tried using standard tags and
@php @endphp
directives.
app.blade.php
...ANSWER
Answered 2019-Jan-27 at 22:42You can write it using full path from child template.
QUESTION
Am refering to moneyphp/money library which I plan to use it in one of our projects for dealing with currencies. The Documentation is great except it does not touch how to persist in the database. It speaks about encoding money object to JSON but storing strings makes it difficult to make queries as simple as comparing the amount or currencies.
Going through issues, I have found few discussion about Doctrine and it is so specific to doctrine that I could not benefit anything.
Asking my question, in concise words: How do I store money object without loosing details? I'm interested in Postgresql but any relational database is OK.
Note: I have read many different way to persist monetary in database and they differ in how they do. Am interested in specific way that works with this specific library.
...ANSWER
Answered 2018-Feb-09 at 12:19After tiresome reading of many different threads, posts et al, I have come to the conclusion that only two way are acceptable (see great comments in this question):
Convert all money to smallest unit (eg. Cents) each time you save to the database and reconvert when retrieving it.
Use DECIMAL/NUMERIC data type with needed accuracy (Many recommend NUMERIC(15,4) when doing normal operations or NUMERIC(15, 6) if you do currency exchange operations)
Of course whatever the choice, it must be coupled with Currency column.
I have ended up with the first method because of this library (which is not the original when I asked the question), which makes that super easy. Here are explanations from author after I created an issue:
I can only tell you that I personally store my monies in the database as an integer representing the amount in minor units (cents), and optionally a
CHAR(3)
for the currency if the application uses multiple currencies (otherwise the currency is hardcoded in the app).You can get the amount in minor units this way, as an integer:
$money->getMinorAmount()->toInt();
And you can retrieve a Money from an integer stored in the database using:
Money::ofMinor($integerAmount, 'USD');
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install laravel-money
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page