laravel-cambodia-seeder maintained by phumtech
Laravel Cambodia Geography Seeder
A production-ready Laravel package that provides migrations, seeders, and fully integrated Eloquent Models for Cambodian geography (Provinces, Districts, and Communes).
Installation
You can install the package via Composer once it is published on Packagist:
composer require phumtech/laravel-cambodia-seeder
Setup
First, run the migrations to create the required provinces, districts, and communes tables:
php artisan migrate
Next, seed the database with the pre-packaged geography data:
php artisan cambodia:seed
Usage
This package bundles Laravel Eloquent Models, which allows you to intuitively fetch relationships directly in your app.
The Models
Phumtech\CambodiaSeeder\Models\ProvincePhumtech\CambodiaSeeder\Models\DistrictPhumtech\CambodiaSeeder\Models\Commune
Example
use Phumtech\CambodiaSeeder\Models\Province;
// Get all provinces
$provinces = Province::all();
// Look up a specific province and load its nested districts and communes
$phnomPenh = Province::with('districts.communes')
->where('name_en', 'Phnom Penh')
->first();
// Loop through the data
foreach ($phnomPenh->districts as $district) {
echo $district->name_en . " - " . $district->name_kh . "\n";
foreach ($district->communes as $commune) {
echo "- " . $commune->name_en . "\n";
}
}
Customizing the Data (Optional)
If you need to manually modify or review the CSV datasets used for seeding, you can publish the raw CSVs into your local user app's database/data/cambodia directory using this command:
php artisan vendor:publish --tag=cambodia-data
Once published, running php artisan cambodia:seed will read from your published customizable files rather than the core package defaults.
License
The MIT License (MIT).