- How do I install pharaonic/laravel-locations in a Laravel application?
- Install it with Composer by running composer require pharaonic/laravel-locations. Then publish the package config, migrations and seeders as needed and run your migrations. Load the location data with the provided seeders or helpers, and verify the tables before using the models in your app.
- Which Laravel and PHP versions are supported by laravel-locations?
- The package is a standard Laravel reference-data package, but the exact PHP and Laravel constraints are declared in its composer.json. Check those constraints before upgrading, especially on older Laravel versions. Version 1.5.7 is a patch-level data correction and should not change public APIs. Test the install on your production database engine because collation and unique-index behavior differ across MySQL, PostgreSQL and SQLite.
- What location data does pharaonic/laravel-locations include?
- It provides timezones, continents, countries and states, and the package blurb also describes city data. The data is exposed through Eloquent models with migrations and seeders so you can query it locally. It is reference data, not a runtime geolocation or address-validation service.
- How do I seed countries, states and cities after installing the package?
- Publish the package seeders or use its helper or commands, then run the seeders against your database. Prefer idempotent seeding so repeated runs do not create duplicates or fail on unique constraints. Back up the location tables before re-seeding in staging or production. After seeding, verify that state and city foreign keys resolve correctly.
- How do I fix a duplicate state ISO code after updating to 1.5.7?
- Version 1.5.7 removes a duplicate ISO state entry from the package data, but updating the package does not automatically clean an already-populated database. Back up the state table, detect duplicates scoped by country, then re-run the package seeders or apply a targeted dedupe script. Avoid dropping and recreating tables in production. Verify that cities and application records still reference valid state IDs afterward.
- Can I use laravel-locations for country and state dropdowns in address forms?
- Yes, the models and helpers are designed for building address forms, regional filters and location-aware features. Query countries once, then load states scoped to the selected country to avoid ambiguous ISO lookups. Cache these lists if the forms are rendered frequently. Validate submitted country and state codes server-side rather than trusting the dropdown values.
- Does the package enforce unique state ISO codes per country?
- The TPM assessment flags this as something to verify in your own schema rather than assuming global ISO uniqueness. ISO state codes are typically meaningful only within a country, so uniqueness should be scoped by country. Check the package migrations and indexes, and add a composite unique index on country and state code if your application relies on it. Test on your production database engine before rollout.
- How should I cache location lookups in a high-read Laravel application?
- Country, state and city data is small and read-heavy, so cache lookups instead of querying on every request. Cache countries and country-scoped state lists with a long TTL and clear the cache after any data refresh. Avoid per-request joins across cities, states and countries for simple dropdowns. Monitor stale caches after upgrading or re-seeding because cached duplicates can survive a database fix.
- How do I test a Laravel app after updating laravel-locations location data?
- Update in staging first and run duplicate-detection SQL scoped by country before touching production. Regression-test address forms, regional filters and APIs that return location data, including foreign-key relationships between cities and states. Run your normal test suite against the production database engine, not only SQLite. Deploy with a backup and a rollback plan, then validate affected state and country records.
- Is laravel-locations a good alternative to maintaining my own country and state data?
- It is a lightweight option that avoids a runtime geolocation service and gives Laravel developers models, migrations and seeders out of the box. Ongoing maintenance is low, mostly periodic Composer updates and monitoring for further data corrections. Support risk is moderate if the package is abandoned, but the data can be exported and owned internally. If you need guaranteed freshness or strict ISO governance, consider a data source you control and review future releases for location-data changes.