Any how i intergate laravel i will use this package
composer require stevebauman/location
<?php
namespace App\Http\Controllers\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Stevebauman\Location\Facades\Location;
class SettingController extends Controller
{
public function index()
{
$position = Location::get();
if ($position) {
// Pass the location data to the view
return view('user.settings.index', [
'ip' => $position->ip,
'country' => $position->countryName,
'timezone' => $position->timezone,
]);
} else {
// Handle the case where location data could not be retrieved
return view('user.settings.index', [
'error' => 'Unable to retrieve location information.'
]);
}
}
}
I am not familiar with this specific library but according to the documentation you will need to add your token to the configuration and then enable the IpInfo driver.
<?php
return [
/*
|--------------------------------------------------------------------------
| Driver
|--------------------------------------------------------------------------
|
| The default driver you would like to use for location retrieval.
|
*/
'driver' => Stevebauman\Location\Drivers\IpInfo::class,
// ...
Rerun your code, and you should find that the requests are made to our API instead.
Optional you can update the libraries fallback’s to use the default (IpApi) there instead, e.g: