You can add multiple more checks to see if the data is correct with the rules you set in the statements. cheers!
Check if the number of instructors is too high
if ($data['instructors'] > $maxInstructors) {
if ($data['participants'] > 0) {
$errors['instructors'] = "With participants, a maximum of {$maxInstructors} instructors is allowed for {$workshopsReserved} workshop(s).";
} else {
$errors['instructors'] = "A maximum of {$maxInstructors} instructors is allowed for {$workshopsReserved} workshop(s).";
}
}
If the number of instructors exceeds the allowed limit, an error message is added to the $errors array.
The message changes slightly depending on whether there are participants.
Check if the number of participants is too high
if ($data['participants'] > $maxParticipants) {
$errors['participants'] = "A maximum of {$maxParticipants} participants is allowed for {$workshopsReserved} workshop(s).";
}
if ($data['participants'] > 0 && $data['instructors'] == 0) {
$errors['participants'] = "Participants cannot be registered without instructors.";
}
Ensures that you cannot have participants in a workshop if no instructors are assigned.
Return back with errors if any exist
if ($errors) {
return back()->withErrors($errors)->withInput();
}