Currently I have working foreach array where it collects all tasks and it contains weight for each task.
Here's my working code
foreach ($arr4 as $row4) {
$taskCode = strtoupper(str_random(12));
$insert_data5[] = array(
'projCode' => $projCode,
'taskCode' => $taskCode,
'taskWeight' => $row4['weight'],
'plan_days' => $row4['planned_days'],
'actual_days' => $row4['actual_days'],
'deleted' => 0,
'by_id' => auth()->user()->id,
'updated_by' => auth()->user()->name,
'created_at' => now(),
'updated_at' => now(),
);
}
dd($insert_data5);
OUTPUT
What I'm trying to do is to validate if the sum up of taskWeight of 5 Tasks doesn't reached 100% this will show an error message.
As of now my idea is to use validator but I have no idea how can I calculate the array fields of taskWeight
$validator = Validator::make(
$insert_data5,
[
......
]
);
if($validator->fails()){
return redirect()
->back()
->with(['errors'=>$validator->errors()->all()])
->with('modal',$modal);
}


taskWeightto be less than 100? and what does that5 Tasksmean? did you mean to say you want sum of5 tasksor there are total5 tasks?tasksusingtaskWeightthis should not exceeds 100%. I just want to limit the total sum up into 100% and if the total sum up oftaskWeightis<100there's a validation will appear that says it should be exact 100%$insert_data5contains the data of excel file