- How do I install and set up the World package in Laravel?
- Run `composer require nnjeim/world`, publish the config with `php artisan vendor:publish --tag=world`, then execute migrations and the seeder: `php artisan migrate` followed by `php artisan db:seed --class=WorldSeeder`. The seeder takes ~15 minutes to populate the database.
- What Laravel versions does this package support?
- The package is designed for Laravel 8.x and 9.x. Check the package’s `composer.json` or changelog for specific version compatibility details, as newer Laravel releases may require updates.
- Can I customize the database tables or fields used by the package?
- Yes, you can customize table names and enable/disable optional fields by editing the `world.php` config file after publishing the package assets. This allows you to align the schema with your existing database structure.
- How do I fetch countries with their states and cities using the Facade?
- Use `World::countries(['fields' => 'states,cities', 'filters' => ['iso2' => 'FR']])` to fetch France with its states and cities. The response will include nested arrays for states and cities under each country object.
- Does the package support filtering and pagination for API routes?
- The package supports filtering via query parameters like `/api/countries?filters[iso2]=FR` but does not include built-in pagination. You’ll need to implement pagination manually in your API routes or queries.
- Will this package work in a production environment with high traffic?
- The package is database-backed, so performance depends on your server’s resources and database optimization. For high-traffic apps, consider caching frequently accessed data (e.g., countries) in Redis or implementing database indexing for large datasets like cities.
- How often is the dataset updated, and can I sync it automatically?
- The dataset is static and requires manual seeding via `php artisan db:seed --class=WorldSeeder`. There’s no built-in sync mechanism, so updates (e.g., new countries or currencies) must be handled manually or via custom scripts polling an external API.
- Are there alternatives to this package for Laravel geopolitical data?
- Yes, alternatives include `spatie/laravel-countries` (focused on countries) or `laravel-world/laravel-world` (similar scope). Evaluate based on your needs—some packages offer real-time sync or lighter-weight solutions like JSON files with caching.
- How do I handle API route conflicts with existing Laravel routes?
- The package registers routes under `/api/`. To avoid conflicts, either namespace your routes or prefix them (e.g., `/geo/api/countries`). Check your `routes/api.php` for existing routes and adjust accordingly.
- Can I extend the package to add custom fields or validation logic?
- The package allows customization via the `world.php` config, but extending it to add custom fields or validation requires manual code changes. You’d need to modify the seeder, migrations, or facade logic to support additional logic or constraints.