[英]Update all rows
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 此结果更新第一个$ updateActivity,当第一个worker_activity达到$ a时,进行第二个更新,依此类推。我的任务一次全部更新
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');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.