Reading the repo
Opening the box…
Reading the repo
Opening the box…
How to install on macOS
Retrieve a visitor's location from their IP address.
Saved setup from 2 min ago
Will it work on macOS?
Then run bash setup.sh. It stops at the first error and is safe to run again. Servers and tests aren't started; it lists them at the end. Read it first.
Needs Git: xcode-select --install
git clone https://github.com/stevebauman/location.git cd location
PHP >=8.1
brew install php composer
composer install
use Stevebauman\Location\Facades\Location;
if ($position = Location::get()) {
// Successfully retrieved position.
echo $position->countryName;
} else {
// Failed retrieving position.
}
Important:
- This method retrieves the user's IP address via
request()->ip().- In the default configuration,
testing.enabledis active, the returned IP address is in the USA. Disable it to get the client's real IP address.
Location::get() returns a Stevebauman\Location\Position instance, or false when no driver could
locate the IP address. With the default IpApi driver, the position looks like this:
$position = Location::get('8.8.8.8');
$position->toArray();
[
'ip' => '8.8.8.8',
'driver' => 'Stevebauman\Location\Drivers\IpApi',
'countryName' => 'United States',
'currencyCode' => 'USD',
'countryCode' => 'US',
'regionCode' => 'VA',
'regionName' => 'Virginia',
'cityName' => 'Ashburn',
'zipCode' => '20149',
'isoCode' => null,
'postalCode' => '20149',
'latitude' => '39.03',
'longitude' => '-77.5',
'metroCode' => null,
'areaCode' => null,
'timezone' => 'America/New_York',
]
All values are strings, including latitude and longitude. A field the driver
doesn't provide is null. See Available Fields for what each driver returns.
$position = Location::get('8.8.8.8');
No reports for macOS yet.
GitManual AI Agent reads the 4 key files and writes a step-by-step guide for macOS. Once written, it's saved for everyone.