adamcmoore/laravel-location-validator

Laravel 验证规则,用于检查经纬度对是否在区域内。

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

This package is auto-updated.

Last update: 2024-09-03 11:55:15 UTC


README

Laravel 验证规则,用于检查经纬度对是否在区域内。

安装

composer require adamcmoore/laravel-location-validator

使用

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.