Download the PHP package sebastiansulinski/laravel-currency without Composer

On this page you can find all versions of the php package sebastiansulinski/laravel-currency. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-currency

Currency component for Laravel 9

Installation

Install the package using composer

Service Provider and Facade

To use the package with the IOC Container, add its SSD\Currency\CurrencyServiceProvider to the list of providers inside of the config/app.php under the providers:

To use it as a Facade, add it under the aliases:

now run:

This will add a new file config/currency.php with the following structure:

Provider

Package comes with two implementations / providers:

You can create additional providers by:

There are 3 methods that the new Provider needs to implement - these are: get, set and is. Please see SSD\Currency\Providers\CookieProvider to get a better idea.

Once you have a new implementation ready, create the new ServiceProvider and replace it within config/app.php.

Adding more currencies

Package comes with 3 currencies out of the box: GBP, USD, EUR.

If you'd like to add more, first create a new currency class, which:

For instance, implementation for Japanese Yen would be (assuming you keep your currencies under App\Components\Currencies namespace):

All you need to do now to be able to use it is to add it to the config/currency.php file:

Currencies with symbol after the value

Some currencies place symbol after the value. To indicate it you can overwrite the method BaseCurrency::symbolAfterValue and if you need a space between the symbol and value BaseCurrency::symbolSpace:

The above class would now return 75.00 zł with withSymbol and 75.00 zł PLN with withSymbolAndCode methods.

Usage examples

The most common way of displaying currencies is to either have them displayed as clickable buttons or as a form select menu, which is what I'm going to demonstrate below.

First let's create a form select element with all options displayed. We can either use a Currency facade or simply pull currency from within the container using app('currency'):

Now we need have some JavaScript so that when the change event occurs, the call is made to the given route, where action of the controller sets the new currency and page reloads reflecting that change.

Simply bind change event to the select element using JavaScript:

Next we need to add the Controller with Action and Route for it:

Now if you'd like to display price based on the selected currency, make sure that your model can provider an array of prices for a given item in the following format:

Let's assume our Product model has a prices() method, which will return the array formatted as above. To use it with the currency you can now simply call:

The priceDisplay() method will return the price with the currency symbol i.e. £10.00 (depending on the currently selected currency).

Formatting methods

We have the following methods available on our Currency object instance / facade:

Four of the above methods accept 3 arguments (integer method only first 2):

More methods


All versions of laravel-currency with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
illuminate/http Version ^10.0
illuminate/support Version ^10.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sebastiansulinski/laravel-currency contains the following files

Loading the files please wait ....