32 lines
975 B
PHP
32 lines
975 B
PHP
<?php
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
/**
|
|
* @codeCoverageIgnore
|
|
*/
|
|
class ValidateAuditionKey implements ValidationRule
|
|
{
|
|
/**
|
|
* Validates the given attribute and value to ensure they correspond
|
|
* to an existing audition in the database. If the audition ID does
|
|
* not exist, the validation will fail with the provided message.
|
|
*
|
|
* @param string $attribute The attribute being validated.
|
|
* @param mixed $value The value of the attribute.
|
|
* @param Closure $fail Callback function to indicate validation failure.
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
// Extract the key from the attribute
|
|
$key = explode('.', $attribute)[1];
|
|
if (! DB::table('auditions')->where('id', $key)->exists()) {
|
|
$fail('Invalid audition id provided');
|
|
}
|
|
}
|
|
}
|