Laravel Country, State, City Seeder Package

Nihir Zala
2 min readDec 14, 2023

Hi There I created the library for Laravel developers to make their life easier.

What is this library?

This is a library called CSC aka Country-State-City Seeders. When I was developing, I faced the issues so often that where can I get the seeder files? & how can I manage it? Is there a relationship or not?

So I googled & found some seeders files & with that help, I made this library which already has a relationship between their models.

Why do you need this?

If your project needs the country state & city dropdown & you have no idea about how it works I already made the library for it. Here are some of the points.

Open Source & Free.

Easy to install

Easy to modify

Already have a relationship with Models

How to install it?

You don't need Country State & City Models & migrations if you already have to take a backup and remove the files (Don’t remove backups). Then run the following command.

composer require nihirz/csc
php artisan vendor:publish --provider=Nihirz\csc\CSCServiceProvider

The previous command publishes the files in your project.

Now you can simply run the following commands.

php artisan optimize:clear
php artisan config:cache

This will clear your caches

php artisan migrate

This will migrate the tables into databases.

Now simply add this line to your DataBaseSeeder.php file.

$this->call(CountryStateCityTableSeeder::class);
php artisan db:seed

The db:seed command is for seeding your database

File System

When you publish the files you will get the same files.

Models

You can get the Country, State, and city Moodels in your models directory.

DataProviders

In the App Directory, you will the new directory named DataProviders there are 3 Files

CityDataProvider.php, CountryDataProvider.php & StateDataProvider.php

What DataProvider files Contain?

The data provider files contain the data for seeds.

Database

This will contain the files for the database & seeder files

This library is open source so you can contribute to it & if you want to add or update just fork this repository. Install in your local update the changes & then create the pull request I will surely update this

If you face any issues or find some bugs then create the issues on GitHub

If the bug is critical then you can simply mail me.

If you like this library & use it in your projects then don't forget to give it a free star.

You can follow me on social media:

Twitter, Linkedin, Instagram & Github.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Nihir Zala
Nihir Zala

Written by Nihir Zala

Hi there, I'm Nihir Zala—a Laravel developer from Gujrat, India, with over 2.5 years of professional experience. I also learning Penetesting from THM and HTB.

No responses yet

Write a response