In this tutorial, we will see how you can get the current user location, city, country, country code, postal code, zip code, region, longitude and latitude using IP Address in laravel.
So we will be using stevebauman/location package in order to get that information.
So let’s get started.
Step 1: Install Laravel
First, we will install laravel into the project. I am installing it in user_location folder.
composer create-project --prefer-dist laravel/laravel user_location
Step 2: Install stevebauman/location package
Then we need to install the stevebauman/location package.
composer require stevebauman/location
Step 3: Add the Service Provider and Alias
Then we need to add the service provider in config/app.php in providers array:
Stevebauman\Location\LocationServiceProvider::class,
And also add following alias in aliases in config/app.php:
'Location' => Stevebauman\Location\Facades\Location,
So your final providers array will look like this:
And aliases array will look like this:
Top comments (0)