anonaddy/app/Rules/NotLocalDomain.php
2024-03-13 17:35:12 +00:00

33 lines
791 B
PHP

<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;
class NotLocalDomain implements ValidationRule
{
/**
* Indicates whether the rule should be implicit.
*
* @var bool
*/
public $implicit = true;
/**
* Run the validation rule.
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$count = collect(config('anonaddy.all_domains'))
->filter(function ($domain) use ($value) {
return Str::endsWith(strtolower($value), '.'.$domain) || strtolower($value) === $domain;
})
->count();
if ($count !== 0) {
$fail('The domain cannot be a local one.');
}
}
}