Skip to main content

Installation

This guide will walk you through installing and configuring Laravel Location in your Laravel application.

Requirements

  • PHP >= 8.1
  • Laravel >= 10.0
  • Database (MySQL, PostgreSQL, SQLite, or SQL Server)

Installation Steps

Step 1: Install via Composer

composer require jobmetric/laravel-location

Step 2: Publish Configuration (optional)

If you need to override the default table names, publish the configuration file:

php artisan vendor:publish --tag=location-config

This will create config/location.php.

Step 3: Publish Migrations (optional) and migrate

Publish migrations:

php artisan vendor:publish --tag=location-migrations

Then run:

php artisan migrate

Laravel Location ships with a dataset workflow to generate and import countries and subdivisions.

Generate/update countries.json:

php artisan location:generate-countries --pretty

Import data:

php artisan location:import

You can also import a single country:

php artisan location:import ir --force

Configuration

After publishing the configuration, you can customize the package behavior in config/location.php:

return [
"tables" => [
'country' => 'location_countries',
'province' => 'location_provinces',
'city' => 'location_cities',
'district' => 'location_districts',
'location' => 'locations',
'location_relation' => 'location_relations',
'geo_area' => 'location_geo_areas',
'geo_area_relation' => 'location_geo_area_relations',
'address' => 'location_addresses',
'address_relation' => 'location_address_relations',
],
];

Next Steps

Now that you have Laravel Location installed, you can: