mirror of
https://github.com/snipe/snipe-it.git
synced 2025-01-07 03:47:32 -08:00
29 lines
729 B
PHP
29 lines
729 B
PHP
|
<?php
|
||
|
|
||
|
namespace App\Rules;
|
||
|
|
||
|
use Closure;
|
||
|
use Illuminate\Contracts\Encryption\DecryptException;
|
||
|
use Illuminate\Contracts\Validation\ValidationRule;
|
||
|
use Illuminate\Support\Facades\Crypt;
|
||
|
|
||
|
class NumericEncrypted implements ValidationRule
|
||
|
{
|
||
|
/**
|
||
|
* Run the validation rule.
|
||
|
*
|
||
|
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||
|
*/
|
||
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||
|
{
|
||
|
try {
|
||
|
$value = Crypt::decrypt($value);
|
||
|
if (!is_numeric($value)) {
|
||
|
$fail($attribute.' is not numeric.');
|
||
|
}
|
||
|
} catch (\Exception $e) {
|
||
|
$fail($e->getMessage());
|
||
|
}
|
||
|
}
|
||
|
}
|