adamcmoore/laravel-location-validator

A Laravel validation rule to check that a lng/lat pair are within an area.

v10.1 2023-07-03 09:29 UTC

This package is auto-updated.

Last update: 2024-04-03 10:59:33 UTC


README

A Laravel validation rule to check that a lng/lat pair are within an area.

Installation

composer require adamcmoore/laravel-location-validator

Usage

use AcMoore\LocationValidator\LocationValidator;

// Validate that latitude & longitude is inside an area
$allowed_area = [
	[48.9675969, 1.7440796],
	[48.4711003, 2.5268555],
	[48.9279131, 3.1448364],
	[49.3895245, 2.6119995],
];
$request->validate(
	[
		'latitude'  => 'latitude',
		'longitude' => 'longitude',
	], 
	[
		'latitude' => new LocationValidator(
			$request->get('longitude'), // Longitude needs to be supplied as an argument when using a Rule Object 
			$allowed_area
		)
	]
);


### Todo
- [ ] Add support for latitude & lognitude in same field, like spatial fields or comma seperated.
- [ ] Allow multiple areas.
- [ ] Add validation rule to `Validator::extend` in a service provider.