【发布时间】:2020-06-29 16:34:46
【问题描述】:
我想验证我的输入是 UUID 还是“LAST_QUESTION”。我创建了一个自定义验证规则LastOrUUID,我想在其中使用 UUID 验证规则。我找不到任何方法来做到这一点,也许你知道实现这个的正确方法是什么?我的上下文自定义规则:
class LastOrUUID implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
if ($value === 'LAST_QUESTION' /* || this is uuid */) {
return true;
}
return false;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
// TODO - add translation
return 'This should either be the last question or have a reference to next question!';
}
}
【问题讨论】:
-
我想你的意思是在你的自定义类中继承默认验证!!!
-
@Nazari 是的,那将是理想的。但是我很高兴至少使用
Str::isUuid(),如果它被 Laravel 使用并且没有更好的方法。