I have PHP function that looks like this, and I use it to change assignee of a certain task to employee that was chosen to be replacement for that employee in given period. That is I have holiday period in which a person that is on holiday gets their tasks replaced from them to their replacement colleague and it works like this:
public function checkUnfinishedTasksInPeriod(Request $request) {
try {
$id = $request->creator;
$todayDate = date('Y-m-d');
$holidaysData = Holidays::where('employee_replacement_id', +$id)
->where('date_from', '<=', $todayDate)
->where('date_to', '>=', $todayDate)
->where('status', 'director_approved')
->get()
->toArray();
foreach($holidaysData as $data) {
$date_from = $data['date_from'];
$date_to = $data['date_to'];
$user_id = $data['user_id'];
Tasks::where('assigned', +$user_id)
->whereIn('status', ['todo', 'inprogress'])
->whereBetween('deadline', [$date_from, $date_to])
->where('type', 'task')
->where('backlog', false)
->update(['assigned' => +$id]);
}
$output = [
'type' => 'success',
'message' => 'Success',
'data'=> null
];
echo json_encode($output);
} catch (Exception $e) {
var_dump($e->getMessage());
var_dump($e->getLine());
}
}
But for some reason my Tasks collection in MongoDB doesn’t get updated. I have tried multiple different solutions and researched a lot. Does somebody know what is the problem ?
I have tried multiple different functions in which I used directly MongoDB syntax, but to no avail. I have researched is there some problem with foreach and update in PHP, is there a problem with eloquent and foreach and so on.