Laravel package for Countries, State / Province, and Cities
mark-villudo/countries-states-cities is a Laravel package for laravel package for countries, state / province, and cities.
It currently has 1 GitHub stars and 732 downloads on Packagist.
Install it with composer require mark-villudo/countries-states-cities.
Discover more Laravel packages by mark-villudo
or browse all Laravel packages to compare alternatives.
Last updated
Laravel package for addresses that mostly used for dropdown in form.
composer require mark-villudo/countries-states-cities
'providers' => [
// ...
MarkVilludo\CountryStateCities\ServiceProvider::class,
];
You can publish the migration with:
php artisan vendor:publish --provider="MarkVilludo\CountryStateCities\ServiceProvider" --tag="migrations"
Then, run
php artisan migrate
You can publish the seeder with:
php artisan vendor:publish --provider="MarkVilludo\CountryStateCities\ServiceProvider" --tag="seeder"
Declare published seeder in DatabaseSeeder.php
public function run()
{
$this->call(CountryTableSeeder::class);
$this->call(ProvincesTableSeeder::class);
$this->call(CitiesTableSeeder::class);
}
Then, run
php artisan db:seed
You can publish its default controllers
php artisan vendor:publish --provider="MarkVilludo\CountryStateCities\ServiceProvider" --tag="controllers"
php artisan make:resource CountryResource
php artisan make:resource ProvinceResource
php artisan make:resource CityResource
php artisan make:model Models/Country
php artisan make:model Models/Province
php artisan make:model Models/City
Route::prefix('v1')->group(function () {
//Country, Province/State and City
Route::prefix('countries')->group(function () {
Route::get('/','Api\CountryController@index');
Route::get('/{id}/provinces','Api\ProvinceController@index');
});
Route::prefix('provinces')->group(function () {
Route::get('/{id}/cities','Api\CityController@index');
});
});
//Serve app. php artisan serve
//Access the url from the code added in routes/api.php
http://127.0.0.1:8000/api/v1/countries
http://127.0.0.1:8000/api/v1/countries/169/provinces
http://127.0.0.1:8000/api/v1/provinces/46/cities
The MIT License (MIT). Please see License File for more information.