更新laravel中超过72小时的记录
实际上,我的场景是用户通过支付硬币向另一个用户发送请求,如果用户在72小时内不接受请求,那么硬币应该交给用户 我正在把硬币放在硬币桌上 如果记录超过72小时,我如何更新记录,我已尝试使用以下代码更新laravel中超过72小时的记录,laravel,laravel-5.5,Laravel,Laravel 5.5,实际上,我的场景是用户通过支付硬币向另一个用户发送请求,如果用户在72小时内不接受请求,那么硬币应该交给用户 我正在把硬币放在硬币桌上 如果记录超过72小时,我如何更新记录,我已尝试使用以下代码 public function getAllRequests(Request $request) { $expired_details = MenterRequest::where('created_at', '<', Carbon::now()->subHours(72)->
public function getAllRequests(Request $request)
{
$expired_details = MenterRequest::where('created_at', '<', Carbon::now()->subHours(72)->toDateTimeString())->get();
foreach($expired_details as $expired)
{
$msubIds = $expired->menter_subscriber_id;
$update =Coins::where('user_id','=',$msubIds)->update([
'mcoins','=>','2000001'
]);
}
}
公共函数getAllRequests(请求$Request)
{
$expired_details=MenterRequest::where('created_at','','2000001'
]);
}
}
我可以获得超过72小时的行,现在如何更新它们您可以使用相同的foreach循环来更新所有过期的行
foreach($expired_details as $expired)
{
$msubIds = $expired->menter_subscriber_id;
$update =Coins::where('user_id','=',$msubIds)->update([
'mcoins','=>','2000001'
]);
/* Update your rows and save the data */
$mentor_update = MenterRequest::find($expired->mentor_id);
$mentor_update->your_column = your_data;
$mentor_update->save();
}
希望这有帮助。:) 试试这个
foreach($expired_details as$expired){$expired->mcoins='2000001';$expired->save()}
hello@Maraboc的可能重复项我的问题是如何更新超过72小时的行。是的,我知道通过这个查询可以得到超过72小时的记录$expired_details=MenterRequest::where('created_at','是的,成功了,谢谢@Maraboc