4,000 emails/month for free | Mailtrap sends real emails now!

Location

stevebauman/location image

Location stats

Downloads
3M
Stars
912
Open Issues
11
Forks
167

View on GitHub →

Retrieve a user's location by their IP Address

Laravel Location Package Summary

Laravel Location is a versatile package for retrieving a user's geographical location based on their IP address. It supports multiple services and is easy to integrate with Laravel projects.

Key Features

  • Multiple Drivers: Supports various services like IpApi, IpData, IpInfo, and more, including the ability to set up a local MaxMind database.
  • Fallback Drivers: Automatically uses fallback drivers if the primary fails, ensuring reliability.
  • Custom Driver Support: Developers can create and integrate custom location drivers.
  • IP Address Specific Location: Retrieve location data for any specified IP address.
  • Configurable and Extendable: Includes publishable config files for easy customization.

Installation

Install via composer:

composer require stevebauman/location

Publish the configuration file:

php artisan vendor:publish --provider="Stevebauman\Location\LocationServiceProvider"

Usage

Retrieve the location of the client's IP:

use Stevebauman\Location\Facades\Location;
 
if ($position = Location::get()) {
echo $position->countryName;
} else {
// Handle failure
}

Retrieve the location for a specific IP:

$position = Location::get('192.168.1.1');

Setting Up Drivers

MaxMind Local Setup

  1. Create an account and obtain a license key from MaxMind.
  2. Add the MAXMIND_LICENSE_KEY to your .env file.
  3. Run php artisan location:update to download and set up the local database.

Custom Drivers

Create by extending the Driver or HttpDriver classes, and configure in location.php.

Upgrading from v6

Version 7 introduces strict types, updated dependencies, and a new driver structure. Custom drivers need to be updated to match the new base classes.

Versioning

Follows Semantic Versioning. Major updates may break backward compatibility, while minor and patches focus on new features and bug fixes respectively.

This package is ideal for developers needing to implement IP-based geolocation in their Laravel applications with flexibility and ease.

stevebauman photo

I like to build things on the web 💻

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Stevebauman Location Related Articles

Laravel 12.51.0 Adds afterSending Callbacks, Validator whenFails, and MySQL Timeout image

Laravel 12.51.0 Adds afterSending Callbacks, Validator whenFails, and MySQL Timeout

Read article
Handling Large Datasets with Pagination and Cursors in Laravel MongoDB image

Handling Large Datasets with Pagination and Cursors in Laravel MongoDB

Read article
Laravel Live UK returns to London on June 18-19, 2026 image

Laravel Live UK returns to London on June 18-19, 2026

Read article
`hasSole()` Collection Method in Laravel 12.49.0 image

`hasSole()` Collection Method in Laravel 12.49.0

Read article
Laravel Deadlock: Manage Technical Debt with Expiring Code Markers image

Laravel Deadlock: Manage Technical Debt with Expiring Code Markers

Read article
12 Days of Eloquent image

12 Days of Eloquent

Read article
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
SaaSykit: Laravel SaaS Starter Kit logo

SaaSykit: Laravel SaaS Starter Kit

SaaSykit is a Multi-tenant Laravel SaaS Starter Kit that comes with all features required to run a modern SaaS. Payments, Beautiful Checkout, Admin Panel, User dashboard, Auth, Ready Components, Stats, Blog, Docs and more.

SaaSykit: Laravel SaaS Starter Kit
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
Lucky Media logo

Lucky Media

Get Lucky Now - the ideal choice for Laravel Development, with over a decade of experience!

Lucky Media
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech