birzha-legalizasia/app/Rules/CategoryRule.php

26 lines
602 B
PHP
Raw Normal View History

<?php
namespace App\Rules;
use App\Models\Category;
use Illuminate\Contracts\Validation\InvokableRule;
class CategoryRule 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)
{
2022-08-12 08:53:03 +00:00
$category = Category::find((int)$value);
if(!$category){
2022-08-12 08:48:36 +00:00
$fail('There is no :attribute with value: ' . $value);
}
}
}