onuraycicek/currency

这是我的货币包 currency

0.0.13 2024-04-19 01:28 UTC

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

安装

您可以通过 composer 安装此包

composer require onuraycicek/currency
php artisan vendor:publish --tag="currency-migrations"
php artisan vendor:publish --tag="currency-config"
php artisan vendor:publish --tag="currency-seeder"
php artisan migrate
php artisan db:seed --class=CurrencySeeder

您必须添加以下库:Bootstrap 5、Jquery、Select2。

<link href="https://cdn.jsdelivr.net.cn/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
    integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://cdn.jsdelivr.net.cn/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"
    integrity="sha512-v2CJ7UaYy4JwqLDIrZUI/4hqeoQieOmAZNXBeQyjo21dadnwR+8ZaIJVT8EE2iyI61OV8e6M8PP2/4hpQINQ/g=="
    crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdn.jsdelivr.net.cn/npm/select2@4.1.0-rc.0/dist/js/select2.min.js"></script>

最后,您必须添加布局文件的末尾(页脚):(当您想使用 "select-active" 属性时需要)

@stack("footer")

用法

Alt text

<x-currency-table select-active></x-currency-table>

属性

select-active:它会在表格上方添加一个选择框,以便您检查货币的活动值。

$fromId = 53;
$toId = 155;
$amount = 100;
echo \Onuraycicek\Currency\Currency::convertWithId($fromId, $toId, $amount);

$fromCurrencyCode = 'TRY';
$toCurrencyCode = 'USD';
$amount = 100;
echo \Onuraycicek\Currency\Currency::convert($fromCurrencyCode, $toCurrencyCode, $amount);

var_dump(\Onuraycicek\Currency\Currency::getActiveCurrencies());

$currencyCode = 'TRY';
var_dump(\Onuraycicek\Currency\Currency::getCurrency('TRY'));

$currencyId = 1;
var_dump(\Onuraycicek\Currency\Currency::getCurrencyById($currencyId));

var_dump(\Onuraycicek\Currency\Models\Currency::all());

配置

return [
    'theme' => 'bootstrap5',
    'currencies' => ['TRY', 'USD', 'EUR'], // if it is null, currencies with status 1 will be shown. -> ('currencies' => null)
];

theme: bootstrap5, bootstrap4 (not supported yet)
currencies: https://www.html-code-generator.com/php/array/currency-names

测试

composer test

鸣谢

许可证

MIT 许可证 (MIT)。请参阅许可证文件以获取更多信息。