Validation & requests
The package registers Rule::coordinates(), which checks that a value is a coordinate pair within valid latitude and longitude ranges:
use Illuminate\Validation\Rule;
$request->validate([
'point' => ['required', Rule::coordinates()], // "lat,lng", [lat, lng], or ['latitude'=>…, 'longitude'=>…]
]);Accepted input shapes:
// Each of these passes Rule::coordinates():
'48.1486,17.1077'; // "lat,lng" string
[48.1486, 17.1077]; // indexed pair
['latitude' => 48.1486, 'longitude' => 17.1077]; // named keys
['lat' => 48.1486, 'lng' => 17.1077]; // short keys (lon is accepted too)Non-numeric or out-of-range values fail with “The {attribute} must be a valid latitude/longitude coordinate.” The rule class is RoundlyConsulting\Geolocation\Rules\CoordinatesRule if you prefer new CoordinatesRule.
Request macro
Every request gets a location() macro that resolves the client’s Location from its IP through the manager — so it honours your pipeline, cache and the test fake:
$location = $request->location(); // resolves the client's Location from its IP, or nullIt returns null when the request has no IP.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.