adamcmoore / laravel-location-validator
A Laravel validation rule to check that a lng/lat pair are within an area.
Installs: 43
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 2
Forks: 0
Open Issues: 1
Type:package
Requires
- php: ^8.1
- illuminate/console: ^10
- illuminate/database: ^10
- illuminate/filesystem: ^10
- league/geotools: ^1.1
Requires (Dev)
- mockery/mockery: ^1.0
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10
This package is auto-updated.
Last update: 2025-03-03 12:56:30 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.