@andy7 perhaps introduce a validation rule which makes a document field compulsory if $days > 2.
have a look the following on how to make a custom validation rule.
https://laravel.com/docs/8.x/validation#custom-validation-rules
Hello everyone thank you for your time, I'm relatively new and learning, and I'm currently stuck a little at this part, I want to make it possible for each user when they request a sick(medical) leave from the system and if the number difference is bigger than 2 it should require that user to upload a file
So I have finished all these parts the functions to get the number difference and file upload I just need to put an if statement or another statement to check if it's more than 2 how would that be possible?
This is the function that gets the difference of the numbers from 2 dates
public function numberOfDays($id)
{
$datesx =Leave::where('id', $id)
->first();
$from =$datesx->from;
$to =$datesx->to;
$datetime1 = new DateTime($from);
$datetime2 = new DateTime($to);
$datetime2->modify('+1 day');
$interval = $datetime1->diff($datetime2);
$days = $interval->format('%a');
//dd($days);
$period = new DatePeriod($datetime1, new DateInterval('P1D'), $datetime2);
foreach($period as $dt) {
$curr = $dt->format('D');
if ($curr == 'Sat' || $curr == 'Sun') {
$days--;
}
}
return $days;
}
And this is how i upload files on the leaveController on the store function
$request->file('medicalDocument')->storeAs('docs', $request->medicalDocument->getClientOriginalName());
Please or to participate in this conversation.