birzha-legalizasia/app/Rules/TicketRule.php

26 lines
592 B
PHP

<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\InvokableRule;
use App\Models\Ticket;
class TicketRule implements InvokableRule
{
/**
* Run the validation rule.
*
* @param string $attribute
* @param mixed $value
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
* @return void
*/
public function __invoke($attribute, $value, $fail)
{
$ticket = Ticket::find((int)$value);
if(!$ticket){
$fail('There is no :attribute with value: ' . $value);
}
}
}