Skip to main content

Posts

Showing posts from May, 2020

Laravel: Implementing the country based phone input

When you ideate on your next Laravel project, don't forget that feeling, where you are lost in cloud thinking most of the work has been built into the framework. One such task not built into the framework is the country selector and any other data-driven task/feature. The image below is the desired end result.   Components Below are the different components and how to create them. 1. Countries Table and Model : running the command below on a command-line tool from within a Laravel project should help achieve this. php artisan make:model Models\Country -m our Table can be created with the SQL below; CREATE TABLE `countries` ( `id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, `name` VARCHAR(255) NOT NULL, `iso2` VARCHAR(255) NOT NULL, `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ) COLLATE='utf8mb4_unicode_ci' ENGINE=InnoDB; 2. Regions table and Model:  A country might have many regions, each region is not expected to have more than o