Why not just make a $validationRules array and then do $request->validate($validationRules)? e.g.:
$validationRules = [
'some_field' => 'required|min:2|max:100',
'some_other_field' => 'required|accepted',
];
if ($request->hasFile('img1')) {
$validationRules['img1'] = 'image';
}
if ($request->hasFile('img2')) {
$validationRules['img2'] = 'image';
}
$request->validate($validationRules);
But do you even need to do it conditionally? I don't think it'd fail if you just did
$request->validate([
'img1' => 'image',
'img2' => 'image',
]);
But someone correct me if I'm wrong; I haven't tested it out.
As a side note, if your validation code starts to get long and you're still storing it in your controller, you may wanna look into created form request classes to keep your controllers clean (link).