Reputation:
Actualy,my scenario is user send request to another user by paying coins,If user doesn't accept the request below 72 hours the coins should be revered to the user,
Im storing coins in coins table.
How can I update records if records are older than 72 hours,I have tried with below code
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'
]);
}
}
I can get rows older than 72 hour,now how can update them
Upvotes: 2
Views: 544
Reputation: 95
You can use the same foreach loop to update all the expired rows.
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();
}
Hope this helps. :)
Upvotes: 4