Installation Add the package via Composer:
composer require e-commerce-tetradka/geobundle
Publish the configuration (if available):
php artisan vendor:publish --provider="Nitra\GeoBundle\GeoBundleServiceProvider"
Service Provider & Facade
Ensure the service provider is registered in config/app.php under providers:
Nitra\GeoBundle\GeoBundleServiceProvider::class,
Use the facade for quick access:
use Nitra\GeoBundle\Facades\GeoBundle;
First Use Case: Geo Data Sync Sync a basic geographic dataset (e.g., countries, regions, or cities) via CLI:
php artisan geo:sync --type=countries
Verify sync status in the database (check geo_* tables).
Data Synchronization
app/Console/Kernel.php) to run syncs periodically:
$schedule->command('geo:sync')->dailyAt('2:00');
php artisan make:command CustomGeoSync
Override handle() to integrate with your workflow:
public function handle() {
GeoBundle::sync('custom_regions', ['source' => 'your_api']);
}
API Integration
$response = Http::get('https://api.example.com/geo');
$data = GeoBundle::transform($response->json(), 'cities');
GeoBundle::store($data);
Querying Geo Data
$regions = GeoBundle::getRegionsByCountry('US');
$coordinates = GeoBundle::getCoordinates('New York');
GeoBundle::indexWithScout('cities');
GeoBundle::onUpdate(function ($data) {
broadcast(new GeoUpdated($data))->toOthers();
});
GeoBundle::setResource('CityResource');
Database Conflicts
upsert or unique constraints:
GeoBundle::sync('countries', ['upsert' => true]);
if (!GeoBundle::exists('countries')) {
GeoBundle::sync('countries');
}
Rate Limiting
GeoBundle::setRetryPolicy(5, 1000); // Retry 5 times with 1s delay
Time Zones
$schedule->command('geo:sync')->timezone('America/New_York');
php artisan geo:sync --verbose
config/geobundle.php for correct API keys, endpoints, and cache settings.php artisan geo:sync --env=staging
Custom Data Sources
GeoBundle::extend('custom_source', function () {
return new CustomGeoProvider();
});
Transformers
GeoBundle::transformer('custom_format', CustomTransformer::class);
Events
GeoSynced, GeoUpdated):
GeoBundle::onSync(function ($type) {
Log::info("Synced {$type} data");
});
Caching
GeoBundle::cache('regions', 3600); // Cache for 1 hour
How can I help you explore Laravel packages today?