Moving Service From One Place to Another
Barnaby The Bear’s my name, never call me Jack or James, I will sing my way to fame, Barnaby the...
How to Convert Any Number to Words in PHP: A Simple Guide
Hello, friends! In this tutorial, I will teach you how to convert any number into words using Laravel. Whether it's 10, 290, 23,897, or 2,000,220—no matter the size—we can achieve this with a single line of code. Let's dive into a real example to see how to convert any number to words easily.
Step-1: Install laravel
To instal laravel run the below command. If you have already a project you can start with this.
composer create-project --prefer-dist laravel/laravel number-to-word
Step-2: Instal terbilang package
To convert number into words we need to install the terbilang package using the below command.
composer require riskihajar/terbilang:^2.0
Step-3: Add Providers & Aliases
In the $providers array add the service providers for this package.
config/app.php
Riskihajar\Terbilang\TerbilangServiceProvider::class,
'providers' => ServiceProvider::defaultProviders()->merge([
/*
* Package Service Providers...
*/
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
// App\Providers\BroadcastServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Riskihajar\Terbilang\TerbilangServiceProvider::class,
])->toArray(),
Add the facade of this package to the $aliases array.
config/app.php
'Terbilang' => Riskihajar\Terbilang\Facades\Terbilang::class,
'aliases' => Facade::defaultAliases()->merge([
// 'Example' => App\Facades\Example::class,
'Terbilang' => Riskihajar\Terbilang\Facades\Terbilang::class,
])->toArray(),
Our setup is complete. Now let's see how to use it. It's very simple. Just add oneline code in your blade file to convert any number into word.
Usage: Just call the make method from terbilang and put your number or variable to convert into word.
welcome.blade.php
<p>{{ Terbilang::make(1000) }}</p> //output: one thousand
<p>{{ Terbilang::make(2343) }}</p> //output: two thousand three hundred forty-three
<p> {{ Terbilang::make(5098373) }}</p> //output: five million ninety-eight thousand three hundred seventy-three
Video Link: Click to View on Video Tutorial
This package has lot's of feature. you can check it for more details.
https://github.com/riskihajar/terbilang
80 days around the world, we’ll find a pot of gold just sitting where the rainbow’s ending.
Post Your Comments