This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.
Documentation for the package can be found on Lyften.com.
This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.
Home Page: http://lyften.com/projects/laravel-currency
License: BSD 2-Clause "Simplified" License
This provides Laravel with currency functions such as currency formatting and conversion using up-to-date exchange rates.
Documentation for the package can be found on Lyften.com.
I tried to use
Currency::hasCurrency('EUR')
But it seams to return always true.
Then I adopted this solution :
public function hasCurrency($currency)
{
return $currency == $this->getCurrencyCode();
// return isset($this->currencies[$currency]);
}
Appreciate you written such a awesome package!
I not sure why i can't install the package. here is what i got from the composer
The requested package torann/laravel-currency could not be found in any version, there may be a typo in the package name.
Thanks
Running php artisan currency:manage add USD
will result in an INSERT query that attempts to insert an empty string (''
) value into the integer id column which yields the following error on PostgreSQL:
invalid input syntax for integer
and probably something similar on MySQL with relevant strict modes enabled.
This is due to this default array. Since your migration sets the id
column to auto increment
the id
should be dropped from the default array completely.
Hi,
I followed the installation steps but when I tried to run php artisan currency:update
it throws an InvalidArgumentException
with There are no commands defined in the "currency" namespace.
message.
Is there something I missed?
Thanks
Laravel v.4.1.30
The function getCurrencies() returns all the currencies, even when in the comment of the function says that it would return only the active one's.
After installing laravel-currency and doing all the migrations I was unable to reset my database using php artisan migrate:refresh --seed
as it threw an error telling me the class didn't exist. I had to manually move the migration from /vendor/torann/migrations
to my app's migrations folder.
Hello, I used this package to display currencies for an ecomm site but the default settings I use are not working.
I made EUR the default currency in the config.php, but my currency always displays as USD. I have to use EUR as the second parameter in the function to display my currency as EUR.
I've also tried the currency:cleanup and currency:update commands with no success.
Don't know if it's a real problem, but I thought I should submit it.
Thanks.
It would be great if rounding could be implemented into the Currency:format() function, including to which point it would round to (hundreds, tens, unit, 1 decimal point, etc.) and whether to always round up (ceil), always round down (floor) or round to the nearest point.
i'm using cache driver as redis but it not seems to use cached?
my config as follows
'cache_driver' => 'redis',
On Laravel 5.1 the method exist for the class Arr
does not exist. It is has. So this library is not compatible with Laravel 5.1 for this reason. I'll set a PR for a fix.
Hi!
Can you make currency converter in this package, like
$rate = currency($price, 'USD/EUR');
// $rate = ['value'=> $value, 'date' => $date]
$rate->getValue(); // 0.8768
//or
$price = 1;
$convert = currency($price, 'USD', 'EUR');
$convert = 0.8768;
if user default currency is same as in config file I use $inverse method. But if I use for each user different default currency this method can not be used.
Why not add a config file to choose the name of the resulting table?
I was just playing arround with the newer dev version, and trying to get it working but I get an exception if the middleware is activated.
I'll leave you the trace here:
FatalThrowableError in Database.php line 65: Call to a member function keyBy() on array in Database.php line 65 at Database->all() in Currency.php line 212 at Currency->getCurrencies() in Currency.php line 173 at Currency->hasCurrency(null) in CurrencyMiddleware.php line 47 at CurrencyMiddleware->getUserCurrency(object(Request)) in CurrencyMiddleware.php line 26 at CurrencyMiddleware->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CurrencyMiddleware), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50 at VerifyCsrfToken->handle(object(Request), object(Closure)) at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49 at ShareErrorsFromSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62 at StartSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59 at EncryptCookies->handle(object(Request), object(Closure)) at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102 at Pipeline->then(object(Closure)) in Kernel.php line 122 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87 at Kernel->handle(object(Request)) in index.php line 53
If I use filesystem I found this error
ErrorException in Currency.php line 102:
Undefined index: EUR
I need use filesystem for best performance.
Thankssss
I think It's will be great to add more currencies using artisan like this :
php artisan currency:add --currencies=BDT,BHD
or/and using code :
Currency::add([
'BDT', 'BHD'
]);
And this will fetch for data from the Finance yahoo! and update currency table.
Thanks for sharing
when i try to add exchange values for currency it adds 0 for every one of it
I defined in the configuration ('config/packages/torann/currency/config.php') 'EUR' as default. But in my view is 'USD' - why ignored it? Newest version from composer without any modifications. Only i've changed 'USD' in 'EUR'.
Regards,
Dennis
I m just thinking doing this simple thing will make it more Laravel complaint. Not a real issue though :)
Thanks for creating this nice little package BTW.
I tried the command on the documentation:
currency()->create([
'currency_name' => 'U.S. Dollar',
'currency_code' => 'USD',
'currency_symbol' => '$',
'currency_format' => '$1,0.00',
'exchange_rate' => 1.00000000,
'active' => 1,
]);
I get the following error:
Undefined index: code
Move the currency formats to their own file and use the package config file to enable and disable currencies.
Hi,
In the MiddleWare you use reflash method.
This causes other flash messages also to reflash and they keep being reflashed for ever.
I suggest changing
$request->getSession()->reflash();
to
$request->getSession()->keep('currency);
Have you notice that there's a wrong commit reference on Packagist?
https://packagist.org/packages/torann/currency
"dev-master" reference to 76090c7
This doesn't allow to use the latest version of code.
After this:
php artisan vendor:publish --provider="Torann\Currency\CurrencyServiceProvider"
I receive this:
[Illuminate\Database\QueryException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemaimobiliario.currencies' doesn't exist (SQL: select * from `currencies`)
[PDOException]
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sistemaimobiliario.currencies' doesn't exist
Get the following when running Artisan:
Updating currency exchange rates from Finance Yahoo...
[ErrorException]
Object of class DateTime could not be converted to string
currency:update [-o|--openexchangerates]
After upgrading Composer and running migrate again...
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'value' at row 1 (SQL: update currency
set value
= 1.00 , updated_at
= 2014-06-10 18:44:10 where code
= USD)
negative US currency displays as $-3.00 where it is normally appropriate to use -$3.00 or ($3.00). Perhaps just a formatting issue.
It looks this package is causing errors when php artisan optimize is executed during the upgrade progress.
php artisan optimize
[Illuminate\Contracts\Container\BindingResolutionException]
Unresolvable dependency resolving [Parameter #0 [ array $config
]] in class Torann\Currency\Drivers\Database
Using:
Resolved by converting value to a number on line 103
// Update each rate
foreach ($lines as $line)
{
$code = substr($line, 4, 3);
$value = substr($line, 11, 6) * 1.00; //force conversion to number
if ($value)
{
$this->app['db']->table($this->table_name)
->where('code', $code)
->update(array(
'value' => $value,
'updated_at' => new \DateTime('now'),
));
}
}
How can i implement live pull instead of call the code every time?
@currency(12.00, 'USD')
I need to view all available currencies , how can i do that ?
I tried to fetch all currency using Currency::all()
but I found out all()
is an undefined method.
Any idea how can I fetch all data inside the currency table?
When I ran the currency:update
command on my local testing server, the resulting base currency was GBP (that is, the one that got a rate of 1.00000).
However, the same command on our production server resulted in USD getting a value of 1.00000.
Is there a way to ensure the downloaded values are relative to the correct 'base' currency?
I wonder if the service should be registered as singleton.
The current $this->app->bind
doesn't seem to work for me, the currency got reset to null in the service.
public function registerCurrency()
{
$this->app->singleton('currency', function ($app) {
$config = $app->config->get('currency', []);
return new Currency($config, $app['cache']);
});
}
When I add the Middleware to Kernel.php I get the following error on all pages:
FatalThrowableError in CurrencyMiddleware.php line 29:
Call to a member function get() on null
Also, the default currency (which I have set to GBP) is not formatted. If I use Currency::format(15)
the result is simply 15
. If I specify the currency: Currency::format(15,'GBP')
it is properly formatted as £15.00
. Conversion is working.
Hi,
Can we create functional currency()->getCurrencyCode()? then we can short method have show for current symbol.
Command: php artisan vendor:publish --provider="Torann\Currency\CurrencyServiceProvider"
Output:
[Symfony\Component\Debug\Exception\FatalThrowableError]
Call to undefined method Torann\Currency\Facades\Currency::isDeferred()
Came this error, while porting my 4.2 app used 0.1 version to 5.1.*@dev version of laravel.
Thanks,
First of all, thank you for a nice package! Very useful for me.
So, I changed thousand point to NULL in DB currency table and now I get error while artisan update command: Error: Array to string conversion.
I don't need this point in returned value. Any ideas?
I was looking for a function to help me convert between currencies, I couldn't find one in the source -- it would be great if there was a function like this built in:
public static function convert($amount, $fromCode, $toCode) {
$from = app('currency')->getCurrency($fromCode);
$to = app('currency')->getCurrency($toCode);
return ($to['value'] / $from['value']) * $amount;
}
It is not really clear at all that when using the currency
function, specifying a currency code different than the config default will actually convert the amount to the specified currency relative to your default currency. I assumed currency(100, 'JPY')
would give me ¥100.00
, instead I get ¥10,339.00
because my default currency is USD
.
I'm not sure if it's realted to #50 but when I call the currency($number, $from, $to)
I get an exception aswell. I'll leave the trace as well.
It seems to understand that app('currency')
is an array and therefore it can't access the->convert()
in the helpers file.
ErrorException in Database.php line 65: Call to a member function keyBy() on array (View: /home/vagrant/clark-diamonds-app/resources/views/public/order/show.blade.php) in Database.php line 65 at CompilerEngine->handleViewException(object(FatalThrowableError), '1') in PhpEngine.php line 46 at PhpEngine->evaluatePath('/home/vagrant/clark-diamonds-app/storage/framework/views/8700e366dfdca230aaa883aa4acd5515', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'order' => object(Order), 'diamond_info' => array(object(Collection)))) in CompilerEngine.php line 58 at CompilerEngine->get('/home/vagrant/clark-diamonds-app/resources/views/public/order/show.blade.php', array('__env' => object(Factory), 'app' => object(Application), 'errors' => object(ViewErrorBag), 'order' => object(Order), 'diamond_info' => array(object(Collection)))) in View.php line 147 at View->getContents() in View.php line 118 at View->renderContents() in View.php line 83 at View->render() in Response.php line 51 at Response->setContent(object(View)) in Response.php line 202 at Response->__construct(object(View)) in Router.php line 1229 at Router->prepareResponse(object(Request), object(View)) in ControllerDispatcher.php line 112 at ControllerDispatcher->Illuminate\Routing\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102 at Pipeline->then(object(Closure)) in ControllerDispatcher.php line 114 at ControllerDispatcher->callWithinStack(object(OrdersController), object(Route), object(Request), 'show') in ControllerDispatcher.php line 67 at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\OrdersController', 'show') in Route.php line 203 at Route->runWithCustomDispatcher(object(Request)) in Route.php line 134 at Route->run(object(Request)) in Router.php line 708 at Router->Illuminate\Routing\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Authenticate.php line 45 at Authenticate->handle(object(Request), object(Closure)) at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102 at Pipeline->then(object(Closure)) in Router.php line 710 at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 673 at Router->dispatchToRoute(object(Request)) in Router.php line 635 at Router->dispatch(object(Request)) in Kernel.php line 236 at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Debugbar.php line 51 at Debugbar->handle(object(Request), object(Closure)) at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 50 at VerifyCsrfToken->handle(object(Request), object(Closure)) at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 49 at ShareErrorsFromSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 62 at StartSession->handle(object(Request), object(Closure)) at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 59 at EncryptCookies->handle(object(Request), object(Closure)) at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44 at CheckForMaintenanceMode->handle(object(Request), object(Closure)) at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 124 at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) at call_user_func(object(Closure), object(Request)) in Pipeline.php line 102 at Pipeline->then(object(Closure)) in Kernel.php line 122 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 87 at Kernel->handle(object(Request)) in index.php line 53
can this package to convert currency ??
In one of my controllers I want to call Artisan::call('currency:update') but it does not work. The Exception:
CommandNotFoundException in Application.php line 490:
There are no commands defined in the "currency" namespace.
However, in a different part of my application (a Seeder class), Artisan::call('currency:update') works.
So what is causing the crash in the controller?
I'm trying to unistall this package using composer remove torann/currency
but I get this error:
[RuntimeException] >
Error Output: PHP Fatal error: Class 'Torann\Currency\CurrencyServiceProvider' not found in home/myUser/WebProjects/myProject/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 146
How can I clean delete this package?
Function below doesn't give results that one would expect if format involves extra space, dot etc.
currency(12345.6789)
Two examples:
kr 1,0.00
→ kr 12 345,6789
kr. 1,0.00
→ kr. 12.346
Both formats are default so it looks like something doesn't work as it should ;)
The problem is on the the currecy table field 'value'. At the moment is a DOUBLE(15,8) but rise an error on the value 1.00 that is the default currency value, that because try to store a value that contain only 2 decimal. I resolved this changing the field into DECIMAL(17,2) that actually is more precise than DOUBLE. Of course in this way the value is rounded! what you think?
Laravel 5.2
After update currency:
> php artisan currency:update
> [InvalidArgumentException]
> The "openexchangerates" option does not exist.
public function fire()
{
// Get Settings
$defaultCurrency = $this->currency->getConfig('default');
if ($this->input->getOption('openexchangerates')) { //The "openexchangerates" option does not exist
if (!$api = $this->currency->getConfig('api_key')) {
$this->error('An API key is needed from OpenExchangeRates.org to continue.');
return;
}
// Get rates
$this->updateFromOpenExchangeRates($defaultCurrency, $api);
}
else {
// Get rates
$this->updateFromYahoo($defaultCurrency);
}
}
Composer.json
"minimum-stability": "dev",
"laravel/framework": "5.3.*",
"torann/currency": "^1.0",
Composer update after artisan:optimize
[Symfony\Component\Debug\Exception\FatalThrowableError]
Type error: Too few arguments to function Torann\Currency\Drivers\Database::__construct(), 1 passed in /Users/Alex/WEBHOSTS/FHMatchL5/vendor/torann/currency/src/Currency.php on line 255 and exactly 2 expected
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.