How To Get Current Location Details in Laravel 8 Tutorial

Share this Article
Reading Time: 4 minutes

Inside this article we will see the complete concept to get current location details in laravel 8. It will be super easy to understand and very few simple steps to integrate into laravel application.

We will use a composer package which helps us to get the all the details country, zip code, latitude, longitude etc.

This article is not laravel 8 specific even you are free to use in any of your version.

Let’s get started.

Installation of Laravel Application

Laravel Installation can be done in two ways.

  • Laravel Installer
  • By using composer

Laravel Installer

To install Laravel via Laravel installer, we need to install it’s installer first. We need to make use of composer for that.

$ composer global require laravel/installer

This command will install laravel installer at system. This installation is at global scope, so you type command from any directory at terminal. To verify type the given command –

$ laravel

This command will open a command palette of Laravel Installer.

To create ad install laravel project in system,

$ laravel new blog

With the name of blog a laravel project will be created at your specified path.

By using composer

Alternatively, we can also install Laravel by Composer command create-project.

If your system doesn’t has composer Installed, Learn Composer Installation Steps.

Here is the complete command to create a laravel project-

$ composer create-project --prefer-dist laravel/laravel blog

After following these steps we can install a Laravel application into system.

To start the development server of Laravel –

$ php artisan serve

This command outputs –

Starting Laravel development server:

Assuming laravel already installed at system.

Install Composer Package

Open project into terminal and run this composer command to install this Location package.

$ composer require stevebauman/Location

It will install all needed package files into /vendor folder.

Configure Package in Application

Open app.php file from /config folder.

Search for providers, add this line to into array



Search for aliases, add this line to into array


'Location' => 'Stevebauman\Location\Facades\Location',

Publish Configuration Files

Open project in terminal and run this command to publish the files.

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

Create Controller

Go to terminal and run this artisan command to create controller file.

$ php artisan make:controller LocationController

It will create LocationController.php at /app/Http/Controllers folder.

Open file LocationController.php and write this complete code into it.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Location;

class LocationController extends Controller
    public function ip_details()
        // Put your IP address
        $ip = ''; 

        $data = Location::get($ip);
        return view('details', compact('data'));

Create Blade Layout File

Go to /resources/views folder and create a file details.blade.php.

Open details.blade.php and write this complete into it,


    <title>Current Location Details in Laravel 8</title>
        .box {
            margin: auto;
            width: 50%;
            border: 3px dashed green;
            padding: 10px;
            text-align: center;


<body style="text-align: center;">
    <h1>Current Location Details in Laravel 8</h1>
    <div class="box">
        <h3>IP: {{ $data->ip }}</h3>
        <h3>Country Name: {{ $data->countryName }}</h3>
        <h3>Country Code: {{ $data->countryCode }}</h3>
        <h3>Region Code: {{ $data->regionCode }}</h3>
        <h3>Region Name: {{ $data->regionName }}</h3>
        <h3>City Name: {{ $data->cityName }}</h3>
        <h3>Zipcode: {{ $data->zipCode }}</h3>
        <h3>Latitude: {{ $data->latitude }}</h3>
        <h3>Longitude: {{ $data->longitude }}</h3>


Create Routes

Open web.php file from /routes folder. We need to add a route into it.

# Add this to header
use App\Http\Controllers\LocationController;

Route::get('ip-details', [LocationController::class, 'ip_details'])->name('ip_details');

Application Testing

Open project to terminal and type the command to start development server

$ php artisan serve


We hope this article helped you to learn about How To Get Current Location Details in Laravel 8 Tutorial in a very detailed way.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Find More on Laravel 8 Articles here