Skip to content
This repository has been archived by the owner on Sep 18, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
Traineratwot committed Jan 18, 2024
2 parents fa09946 + 2bc3322 commit fc01b8e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/Forms/Components/MapInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function saveAsArray(): static
protected function parseInput(mixed $state): array
{
$validator = Validator::make([
'state' => $state
'state' => $state,
], [
'state' => ['required', new GeoPoint()],
]);
Expand All @@ -116,6 +116,7 @@ protected function parseInput(mixed $state): array
'longitude' => $state['coordinates'][0],
];
}

return [
'latitude' => (float) $state[0],
'longitude' => (float) $state[1],
Expand All @@ -124,11 +125,13 @@ protected function parseInput(mixed $state): array

if (is_string($state)) {
$_state = explode(',', $state);

return [
'latitude' => (float)$_state[0],
'longitude' => (float)$_state[1],
'latitude' => (float) $_state[0],
'longitude' => (float) $_state[1],
];
}

return [
'latitude' => $this->latitude,
'longitude' => $this->longitude,
Expand Down
14 changes: 7 additions & 7 deletions src/Rules/GeoPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class GeoPoint implements ValidationRule
/**
* Run the validation rule.
*
* @param Closure(string): PotentiallyTranslatedString $fail
* @param Closure(string): PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
Expand All @@ -32,8 +32,8 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
}

$point = [
'latitude' => (float)$_value[0],
'longitude' => (float)$_value[1],
'latitude' => (float) $_value[0],
'longitude' => (float) $_value[1],
];
}
if (is_array($value)) {
Expand All @@ -42,16 +42,16 @@ public function validate(string $attribute, mixed $value, Closure $fail): void
'latitude' => $value['coordinates'][1],
'longitude' => $value['coordinates'][0],
];
} else if (count($value) !== 2) {
} elseif (count($value) !== 2) {
$fail("The {$attribute} must be a valid geo point.");
} else {
$point = [
'latitude' => (float)$value[0],
'longitude' => (float)$value[1],
'latitude' => (float) $value[0],
'longitude' => (float) $value[1],
];
}
}
if (!is_numeric($point['latitude']) || !is_numeric($point['longitude'])) {
if (! is_numeric($point['latitude']) || ! is_numeric($point['longitude'])) {
$fail("The {$attribute} must be a valid geo point.");
}
if ($point['latitude'] < -90 || $point['latitude'] > 90) {
Expand Down

0 comments on commit fc01b8e

Please sign in to comment.