bizmitra/amountinwords

A package to convert amount into words

Maintainers

Package info

github.com/mkr2005/amountinwords

pkg:composer/bizmitra/amountinwords

Statistics

Installs: 24

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.1.2 2024-10-20 14:17 UTC

This package is auto-updated.

Last update: 2026-02-20 17:24:23 UTC


README

A simple Laravel package to convert numeric amounts into their equivalent words.

Installation

You can install the package via Composer. Run the following command in your Laravel project's root directory:

composer require bizmitra/amountinwords

Usage
Step 1: Service Provider Registration
Laravel should automatically detect the service provider. However, if you want to manually register it, add the following line to the providers array in your config/app.php file:

'providers' => [
    // Other Service Providers

    Bizmitra\Amountinwords\AmountinwordsServiceProvider::class,
],


Step 2: Using the Package
You can use the PrintAmountInWords class in your controllers or anywhere in your Laravel application. Here’s an example:

Example Controller
Create a new controller using the following command:

php artisan make:controller AmountController


Then, use the following code in your AmountController.php:

<?php

namespace App\Http\Controllers;

use Bizmitra\Amountinwords\PrintAmountInWords;

class AmountController extends Controller
{
    protected $amountInWords;

    public function __construct(PrintAmountInWords $amountInWords)
    {
        $this->amountInWords = $amountInWords;
    }

    public function index()
    {
        $amount = 12345; // Example amount
        $words = $this->amountInWords->displayWords($amount);

        return response()->json([
            'amount' => $amount,
            'in_words' => $words,
        ]);
    }
}
Step 3: Create a Route
You can create a route to access the controller in your routes/web.php (or routes/api.php) file:

use App\Http\Controllers\AmountController;

Route::get('/amount-in-words', [AmountController::class, 'index']);

Usage
   $amount = 4500.00; // Example amount
    // Call the correct method to convert amount to words with currency names
    $words = $this->amountInWords->amountToWords($amount, 'USD', 'cents');

    return response()->json([
        'amount' => $amount,
        'in_words' => $words,

Step 4: Accessing the Functionality
Now, when you access the /amount-in-words route in your browser or through an API client like Postman, you should get a JSON response with the amount in words:

Step 5: Testing the Functionality
Make sure to test your functionality by accessing the route you created and verifying that it returns the correct output.

License
This package is licensed under the MIT License.

Author
Bizmitra ERP
Mahendrasinh Rana & Vishal
Email: mkr@bizmitra.io