I'm really surprised to not find this mentioned anywhere,
Required rules cannot be ignored, use sometimes https://laravel.com/docs/master/validation#conditionally-adding-rules
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm really surprised to not find this mentioned anywhere, which makes me think I'm doing this wrong. He's my scenario:
I have a form with Name and URL. The Name is a required field. But what if you want to update just the URL? In that case the name is not required, because it's already there. But I want to keep the same formRequest for validation because it contains other validation rules (valid URL, max, min, unique etc.). I have solved the problem like this:
public function rules()
{
$requiredFields = [
'name'
];
$rules = [
'name' => 'max:255|unique:tableName,name',
'url' => 'url|max:255'
];
if ($this->method() == 'POST') {
foreach ($rules as $field => $rule)
{
if (in_array($field, $requiredFields))
{
$rules[$field] .= '|required';
}
}
}
return $rules;
}
But ...really? This is not an issue for anyone else? What am I missing?
Please or to participate in this conversation.