如果$this->language()
返回en
,如何仅将alpha_num
添加到验证中?
public function rules()
{
return [
'title' => ['required', 'alpha_num'],
];
}
public function language()
{
// For brevity I only return "en", it could be other languages
return 'en';
}
use IlluminateValidationRule;
public function rules()
{
return [
'title' => ['required', Rule::when($this->language() === 'en', ['alpha_num'])],
];
}