Skip to content

Commit

Permalink
feat: latitude and longitude rules (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dipesh79 authored Jan 22, 2024
1 parent 59dae59 commit ffbe357
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"src/helpers.php"
],
"psr-4": {
"AchyutN\\Traits\\": "src/Traits/"
"AchyutN\\Traits\\": "src/Traits/",
"AchyutN\\Rules\\": "src/Rules/"
}
},
"autoload-dev": {
Expand Down
25 changes: 25 additions & 0 deletions src/Rules/LatitudeRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace AchyutN\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class LatitudeRule implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (!is_numeric($value)) {
$fail("The $attribute must be a number.");
}

if ($value < -90 || $value > 90) {
$fail("The $attribute must be between -90 and 90.");
}
}
}
25 changes: 25 additions & 0 deletions src/Rules/LongitudeRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace AchyutN\Rules;

use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class LongitudeRule implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
if (!is_numeric($value)) {
$fail("The $attribute must be a number.");
}

if ($value < -180 || $value > 180) {
$fail("The $attribute must be between -180 and 180.");
}
}
}

0 comments on commit ffbe357

Please sign in to comment.