Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Latitude And Longitude Rules #7

Merged
merged 1 commit into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
}
}
}
Loading