notchpay / laravel-toolkit
这是我的laravel-toolkit包
2.1.2
2023-06-25 20:06 UTC
Requires
- php: ^8.1
- illuminate/contracts: ^9.0|^10.0
- rennokki/laravel-eloquent-query-cache: ^3.4
- spatie/laravel-package-tools: ^1.13.0
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
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
变更日志
请参阅CHANGELOG了解最近更改的详细信息。
贡献
请参阅CONTRIBUTING了解详细信息。
安全漏洞
请参阅我们的安全策略了解如何报告安全漏洞。
鸣谢
许可协议
MIT许可(MIT)。请参阅许可文件了解更多信息。