take(100)->get(); foreach ($bots as $bot) { WebSocketDialogMsg::whereUserid($bot->bot_id) ->where('created_at', '<=', Carbon::now()->subDays($bot->clear_day)) ->orderBy('id') ->chunk(1000, function ($msgs) { $ids = $msgs->pluck('id')->toArray(); if ($ids) { WebSocketDialogMsg::deleteMsgs($ids); } }); $bot->clear_at = Carbon::now()->addDays($bot->clear_day); $bot->save(); } } public function end() { } }