пакет torann/currency
https://lyften.com/projects/laravel-currency/doc/
установил этот пакет
Код: Выделить всё
composer require torann/currency
Код: Выделить всё
php artisan vendor:publish --provider="Torann\Currency\CurrencyServiceProvider" --tag=config
php artisan vendor:publish --provider="Torann\Currency\CurrencyServiceProvider" --tag=migrations
Код: Выделить всё
php artisan migrate
Код: Выделить всё
php artisan currency:manage add usd,sek
config/currency.php
Код: Выделить всё
'api_key' => env('OPEN_EXCHANGE_RATE_KEY'),
Код: Выделить всё
php artisan currency:update -o
Код: Выделить всё
'default' => env('DEFAULT_CURRENCY', 'USD'),
Код: Выделить всё
protected $middlewareGroups = [
'web' => [
...
\Illuminate\Session\Middleware\StartSession::class,
\Torann\Currency\Middleware\CurrencyMiddleware::class,
...
],
];
Код: Выделить всё
public function handle(Request $request, Closure $next)
{
if (! $request->get('currency') && ! $request->getSession()->get('currency')) {
$request->getSession()->put([
'currency' => 'SEK',
]);
}
return $next($request);
}
конвертируется валюта
Код: Выделить всё
{{ currency(5.99, 'USD', currency()->getUserCurrency()); }}
Код: Выделить всё
USD
Kr

Любое решение, спасибо
Подробнее здесь: https://stackoverflow.com/questions/787 ... in-laravel
Мобильная версия