How to get Country City Address from IP Address Laravel?
Here, I will show you laravel get country city and address from ip. let’s discuss about laravel get location from ip. I explained simply about laravel geolocation. This post will give you a simple example of laravel ip location. Here, Creating a basic example of laravel get user location.
Sometimes, we may require to get user information from ip address in laravel 5, laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 application at that time this article can help to get info from IP.
We can get information from IP Address using "stevebauman/location" composer package for Laravel. "stevebauman/location" through we can get info like country Name, country Code, region Code, region Name, city Name, zip Code, iso Code, postal Code, latitude, longitude, metro Code, metro Code. They will provide bellow following details that they can get from IP.
So first we require to install "stevebauman/location" composer package by using following command.
composer require stevebauman/location
After successfully install package, open
config/app.php file and add service provider and alias.
config/app.php
'providers' => [
....
Stevebauman\Location\LocationServiceProvider::class,
],
'aliases' => [
....
'Location' => 'Stevebauman\Location\Facades\Location',
]
we have to also make public configuration file by following command, after run this command you will find config/location.php file. So run bellow command:
php artisan vendor:publish
Now we are ready to get Location details from user Ip, so you can write code on your route file like as bellow:
Example:
Route::get('get-ip-details', function () {
$ip = '66.102.0.0';
$data = \Location::get($ip);
dd($data);
});
You will find output like as bellow:
Output
Stevebauman\Location\Position Object
(
[countryName] =>
[countryCode] => US
[regionCode] =>
[regionName] => California
[cityName] => Mountain View
[zipCode] => 94043
[isoCode] =>
[postalCode] =>
[latitude] => 37.4192
[longitude] => -122.0574
[metroCode] =>
[areaCode] =>
[driver] => Stevebauman\Location\Drivers\IpInfo
)
I hope it can help you...

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel 9 Send Email with PDF Attachment Example
- Laravel Install Tailwind CSS Example
- Laravel Group By with Max Value Query Example
- How to Add Two Factor Authentication with SMS in Laravel?
- How to Remove Composer Package in Laravel?
- Laravel Maatwebsite Excel Increase Font Size Example
- How to Create Seeder with JSON data in Laravel?
- How to Create Dynamic Navigation Bar in Laravel?
- Laravel Group By Date and Sum Example
- Laravel Livewire Click Event Example
- How to Get IP Address in Laravel?
- Which MySQL Datatype use for Store an IP Address?