notchafrica/laravel-toolkit

这是我的包laravel-toolkit

2.1.2 2023-06-25 20:06 UTC

This package is auto-updated.

Last update: 2024-09-26 01:38:23 UTC


README

请在这里添加您的描述。限制为一两段。考虑添加一个小示例。

安装

您可以通过composer安装此包

composer require notchafrica/laravel-toolkit

您可以使用以下命令发布并运行迁移

php artisan vendor:publish --tag="laravel-toolkit-migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="laravel-toolkit-config"

这是已发布配置文件的内容

return [
    "currency" => [
        'default' => 'USD',

        /*
        |--------------------------------------------------------------------------
        | API Key for FOREXAPI
        |--------------------------------------------------------------------------
        |
        | Only required if you with to use the Open Exchange Rates api. You can
        | always just use Yahoo, the current default.
        |
        */

            'api_key' => env(
                "RESTUNIVERE_API_KEY",
            ),

        /*
        |--------------------------------------------------------------------------
        | Default Storage Driver
        |--------------------------------------------------------------------------
        |
        | Here you may specify the default storage driver that should be used
        | by the framework.
        |
        | Supported: "database", "filesystem", "Model"
        |
        */

            'driver' => 'filesystem',

        /*
        |--------------------------------------------------------------------------
        | Default Storage Driver
        |--------------------------------------------------------------------------
        |
        | Here you may specify the default cache driver that should be used
        | by the framework.
        |
        | Supported: all cache drivers supported by Laravel
        |
        */

        'cache_driver' => null,

        /*
        |--------------------------------------------------------------------------
        | Storage Specific Configuration
        |--------------------------------------------------------------------------
        |
        | Here you may configure as many storage drivers as you wish.
        |
        */

        'drivers' => [

            'database' => [
                'class' => \Notch\Toolkit\Currency\Drivers\Database::class,
                'connection' => null,
                'table' => 'currencies',
            ],

            'filesystem' => [
                'class' => \Notch\Toolkit\Currency\Drivers\Filesystem::class,
                'disk' => "local",
                'path' => 'currencies.json',
            ],

            'model' => [
                'table' => 'currencies',
                'class' => \Notch\Toolkit\Currency\Models\Currency::class
            ],

        ],

        /*
        |--------------------------------------------------------------------------
        | Currency Formatter
        |--------------------------------------------------------------------------
        |
        | Here you may configure a custom formatting of currencies. The reason for
        | this is to help further internationalize the formatting past the basic
        | format column in the table. When set to `null` the package will use the
        | format from storage.
        |
        |
        */

        'formatter' => null,

        /*
        |--------------------------------------------------------------------------
        | Currency Formatter Specific Configuration
        |--------------------------------------------------------------------------
        |
        | Here you may configure as many currency formatters as you wish.
        |
        */

        'formatters' => [

            'php_intl' => [
                'class' => \Notch\Toolkit\Currency\Formatters\PHPIntl::class,
            ],

        ],
    ]
];

可选,您可以使用以下命令发布视图

php artisan vendor:publish --tag="laravel-toolkit-views"

货币

Laravel货币工具包使得将多货币定价实现到您的应用程序中变得简单,并存储汇率数据以实现快速实时转换。

用法

使用这些方法的简单方法是通过辅助函数currency()或使用外观。以下示例将使用辅助方法。

转换

这是最常用convert方法的快捷方式,将给定金额转换为提供的货币。

currency($amount, $from = null, $to = null, $format = true)

参数

$amount - 要转换的浮点金额 $from - 金额的当前货币代码。如果未设置,则使用应用程序默认值(见config/notchpay-toolkit.php文件)。 $to - 要转换金额的货币代码。如果未设置,则使用用户设置的货币。 $format - 返回值是否应该格式化。

用法

echo currency(12.00);               // Will format the amount using the user selected currency
echo currency(12.00, 'USD', 'EUR'); // Will format the amount from the default currency to EUR

格式化

快速将给定金额解析为正确的货币格式。这是最常用format方法的快捷方式。

currency_format($amount, $code = null)

管理

轻松添加、更新或从默认存储中删除货币。当货币数据(如符号)发生变化时,这非常有用。

php artisan currency:<action>

参数

 action              Action to perform (hydrate, seed, or cleanup)

播种

用于在本地数据库中播种货币

php artisan currency:seed

更新汇率

从restuniverse.com更新汇率。需要API密钥才能使用Rest Universe。将其添加到配置文件中。

php artisan currency:hydrate

注意:Yahoo已停止使用其汇率API,因此已从包中删除。

清理

用于清理Laravel缓存的汇率并从数据库中刷新。请注意,使用上述命令之一更新后,缓存的汇率将被清除。

php artisan currency:cleanup

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

安全漏洞

有关如何报告安全漏洞,请参阅我们的安全策略

鸣谢

许可证

MIT许可证(MIT)。有关更多信息,请参阅许可证文件