Reputation: 27
public function postWorkerActivityPlus()
{
$current = Carbon::now();
$WorkerActivity = Model::where('at_work',1)->where('updated_at','<',$current)->get();
$d = $a / $b * $c ;
foreach ($WorkerActivity as $key => $wa) {
$updateActivity = Model::find($wa->id);
if ($wa->worker_activity <= $a) {
$updateActivity->worker_activity += $d;
$updateActivity->save();
return redirect()->back()->with('info', 'You updated worker');
}
}
}
This result updates first $updateActivity, when the first worker_activity reaches $a, proceed to second one etc. My task update all at once
Upvotes: 1
Views: 78
Reputation: 401
change the return position
public function postWorkerActivityPlus()
{
$current = Carbon::now();
$WorkerActivity = Model::where('at_work',1)->where('updated_at','<',$current)->get();
$d = $a / $b * $c ;
foreach ($WorkerActivity as $key => $wa) {
$updateActivity = Model::find($wa->id);
if ($wa->worker_activity <= $a) {
$updateActivity->worker_activity += $d;
$updateActivity->save();
}
return redirect()->back()->with('info', 'You updated worker');
}
Upvotes: 3