notchafrica/laravel-toolkit

This is my package laravel-toolkit

2.1.2 2023-06-25 20:06 UTC

This package is auto-updated.

Last update: 2024-04-26 00:40:41 UTC


README

This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.

Installation

You can install the package via composer:

composer require notchafrica/laravel-toolkit

You can publish and run the migrations with:

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

You can publish the config file with:

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

This is the contents of the published config file:

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,
            ],

        ],
    ]
];

Optionally, you can publish the views using

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

Currency

The Laravel Currency Toolkit makes it easy to implement multi-currency pricing into your application and store the exchange data for fast real-time conversions.

Usage

The simplest way to use these methods is through the helper function currency() or by using the facade. For the examples below we will use the helper method.

Converting

This is a shortcut to the most commonly used convert method, which converts the given amount into the provided currency.

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

Arguments:

$amount - The float amount to convert $from - The current currency code of the amount. If not set, the application default will be used (see config/notchpay-toolkit.php file). $to - The currency code to convert the amount to. If not set, the user-set currency is used. $format - Should the returned value be formatted.

Usage:

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

Formatting

Quickly parse a given amount into the proper currency format. This is a shortcut to the most commonly used format method.

currency_format($amount, $code = null)

Manage

Easily add, update, or delete currencies from the default storage. This is extremely helpful when there are changes to currency data, such as symbols and such.

php artisan currency:<action>

Arguments:

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

Seed

Used to seed currencies in local database

php artisan currency:seed

Updating Exchange

Update exchange rates from restuniverse.com An API key is needed to use Rest Universe. Add yours to the config file.

php artisan currency:hydrate

Note: Yahoo has discontinued the use of their exchange rate API, so it has been removed from the package.

Cleanup

Used to clean the Laravel cached exchanged rates and refresh it from the database. Note that cached exchanged rates are cleared after they are updated using one of the command above.

php artisan currency:cleanup

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.