Pros:
provinces and cities tables with foreign key relationships (province_id) enable complex geographic queries (e.g., filtering users by province or city).latitude/longitude fields for simple geolocation use cases (e.g., distance calculations, map integrations).Cons:
spatie/laravel-geotools) for complex geospatial logic.hasMany, belongsTo), scopes, and accessors.iran-regions:install for one-click setup.last_updated_at field to track data freshness.slug, province_id).Iran::province()->get()).cities tables).composer.json:
composer require shimadotdev/iran-regions
php artisan iran-regions:install
php artisan vendor:publish --provider="Shimadotdev\IranRegions\IranRegionsServiceProvider"
cities/provinces tables.User, Order) to use the package’s relationships:
// app/Models/User.php
public function city()
{
return $this->belongsTo(\Shimadotdev\IranRegions\Models\City::class);
}
// app/Traits/HasLocation.php
trait HasLocation {
public function province()
{
return $this->city->province;
}
}
public function test_user_can_be_filtered_by_province()
{
$tehran = \Shimadotdev\IranRegions\Models\Province::where('slug', 'tehran')->first();
$users = User::whereHas('city.province', fn($q) => $q->where('id', $tehran->id))->get();
$this->assertCount(2, $users); // Example assertion
}
$this->assertEquals('تهران', trans('iranRegions::slug.tehran'));
City/Province models. Use fully qualified namespaces (e.g., \Shimadotdev\IranRegions\Models\City) to avoid collisions.User, Order).How can I help you explore Laravel packages today?