---
title: "Validation & requests — Geolocation for Laravel | Roundly"
description: "Validate latitude/longitude input with Rule::coordinates() and resolve the visitor’s location with the $request->location() macro."
url: https://roundly-consulting.com/open-source/docs/geolocation-for-laravel/validation
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Geolocation for Laravel](https://roundly-consulting.com/open-source/docs/geolocation-for-laravel.md)

# Validation & requests

The package registers Rule::coordinates(), which checks that a value is a coordinate pair within valid latitude and longitude ranges:

```php
use Illuminate\Validation\Rule;

$request->validate([
    'point' => ['required', Rule::coordinates()],   // "lat,lng", [lat, lng], or ['latitude'=>…, 'longitude'=>…]
]);
```

Accepted input shapes:

```php
// 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)
```

The rule checks latitude in \[-90, 90\] and longitude in \[-180, 180\]. The class is RoundlyConsulting\\Geolocation\\Rules\\CoordinatesRule if you prefer new CoordinatesRule.

## Translated messages

Both failures — a value that isn’t a recognisable pair and one out of range — use one translated message, key geolocation::validation.coordinates. It follows the app locale, and :attribute becomes the field’s display name (home\_location reads “home location”) or your validation.attributes entry, as with Laravel’s own rules. English and Slovak ship with the package:

| Locale | Message |
| --- | --- |
| `en` | The :attribute must be a valid latitude/longitude coordinate. |
| `sk` | Pole :attribute musí obsahovať platné súradnice (zemepisnú šírku a dĺžku). |

To change the wording or add a language, publish the files and edit them in lang/vendor/geolocation:

```bash
php artisan vendor:publish --tag="geolocation-translations"
```

When you call the rule’s validate() directly, your closure receives the message already translated, with :attribute still in it.

## 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:

```php
$location = $request->location();   // resolves the client's Location from its IP, or null
```

It 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 crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/geolocation-for-laravel.md)
