ridwaanzan/worldcurrency

Laravel的全球货币

1.1.6 2023-11-15 20:13 UTC

This package is auto-updated.

Last update: 2024-09-15 21:51:48 UTC


README

License Latest Stable Version

ridwaanzan/worldcurrency 是一个为全球货币提供支持的Laravel包。该包将为您的Laravel项目添加迁移文件、种子(用于将数据导入数据库)和模型。

所有货币数据将保存到数据库中,如果您想获取货币数据,可以通过模型访问。

所有货币数据均来自微软官方网站,获取日期为:2023年10月26日。来源:https://learn.microsoft.com/en-us/linkedin/shared/references/reference-tables/currency-codes

快速安装

在您的Laravel项目根目录下打开命令行或终端,并运行以下命令来安装包

composer require ridwaanzan/worldcurrency

支持的版本

注册服务提供者

Laravel

如果您想尝试在Laravel 6或更早的版本中使用此包,在执行迁移时可能会出错。

为确保使用服务提供者类,您可以在文件 config/app.php 中打开并添加类 IndoRegionServiceProvider 到服务提供者数组中

// Provider Lain
Ridwaanzan\Worldcurrency\WorldcurrencyServiceProvider::class,

发布文件

在您的命令行或终端中运行此命令

php artisan worldcurrency:publish

运行命令时,它将复制文件

  • 迁移文件从 /packages/ridwaanzan/worldcurrency/src/database/migrations/database/migrations
  • 种子文件从 /packages/ridwaanzan/worldcurrency/src/database/seeds/database/seeds
  • 模型文件从 /packages/ridwaanzan/worldcurrency/src/database/models/app/Models

运行发布命令后,您应该运行以下命令

composer dump-autoload

迁移和种子

您必须运行此命令将世界货币的数据插入到您的数据库中

php artisan migrate

导入世界货币数据

php artisan db:seed --class=WorldCurrencySeeder

基本用法

您可以将此代码示例添加到Laravel项目的控制器中

<?php

use App\Models\WorldCurrency;

// Get all currencies data
$currencies = WorldCurrency::all();

// Search data or find data using id.
$currencies = WorldCurrency::where('code', 'IDR')->first();

$currencyByName = WorldCurrency::where('currency_name', 'LIKE', '%rupiah%')->first();

$currencyByCountry = WorldCurrency::where('country', 'LIKE', '%indonesia%')->first();

信息

If there's a bug, you can mail me to: ridwan.haqi@gmail.com