Laravel 8.0 Get Country, City & Address From IP Address example

  • 2 mins read

Hello artisan, Today I am going to show an interesting topic about fetching user info in Larave 8.0. In Laravel 8.0 you can get Country, City, and address is very easy to find using stevebauman/location package.

If you are using the laravel app, you might want to retrieve personal data (country name, country code, area code, city name, zip code, iso code, postal code, latitude, longitude, metro code, metro code) from the laravel 8 app’s from ip address. So, this article will teach you get user details from the IP.

Read Also

Install “stevebauman/location”

composer require stevebauman/location

You can find the official GitHub repository here.

Configuration the “stevebauman/location” package

'providers' => [
'aliases' => [
    'Location' => 'Stevebauman\Location\Facades\Location',

Publish the configuration file (this will create a location.php file inside the config/ directory):

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

or by running bellow command

php artisan vendor:publish

Add Routes



 public function getLocation(Request $request)

        if ($position = Location::get()) {
            echo $position->countryName;
        } else {
            echo "Can't fetch!";

Run the Application

php artisan serve



United States

Hope, It helps