Blog Detail

11

Aug
An Automated Version of Country Codes Database in Laravel cover image

arrow_back An Automated Version of Country Codes Database in Laravel

The Country Codes package is a Composer plugin that provides an automated version of the Country Codes database. This database includes country, iso-codes, country names, country names with phone codes, phone codes as well an admin page to manage your list of data.

What this package can do?

  • Get users country names
  • Get users phone numbers
  • Send OTP codes
  • Send messages on messengers
    Usage of this package varies, those were just small examples of what you can do.

Also, my main reason to build this package was to send WhatsApp messages (specifically OTP codes).

Installation

The only thing you need to do to make this work is to add this package as a dependency to your project:

composer require irando/country-codes

Usage

Add following line in your config/app.php file
'providers' => [
    // ...
    Irando\CountryCodes\CountryCodesServiceProvider::class,
];

Run either of the commands below to publish package files

php artisan vendor:publish

And select id referred to:

Irando\CountryCodes\CountryCodesServiceProvider

OR

php artisan vendor:publish --tag=country-codes

Run this command to add countries table into your database

php artisan migrate

Next, Run this command to seed countries data into countries table.

php artisan db:seed --class=CountryCodesTableSeeder

Note: In case of error after this command run composer dumpautoload and try again to seed database

Now visit your_url.tld/country-codes and you are set.

Customization

If you need (probably you do!) to customize the look, routing, functionality, etc. of this package, at stage 2 of installation we deployed CountryCodes.php which is your table model, as well as view files at resources/views/vendor/irando/country-codes you can edit those files and create your own.

For more details, Please visit Github

Published at : 11-08-2022

Author : Rizwan Aslam
AUTHOR
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch your project

Launch project