get(); $requests = ServiceRequest::query()->latest()->limit(10)->get(); $actions = ['updated', 'assigned', 'status_changed']; $descriptions = [ 'Изменены параметры заявки.', 'Заявка назначена ответственному специалисту.', 'Изменен статус обработки заявки.', 'Добавлено служебное действие по заявке.', ]; ActivityLog::query() ->where('model_type', ServiceRequest::class) ->whereIn('action', $actions) ->where('ip_address', '127.0.0.1') ->delete(); foreach ($requests as $request) { ActivityLog::query()->create([ 'user_id' => $users->random()->id, 'model_type' => ServiceRequest::class, 'model_id' => $request->id, 'action' => $actions[array_rand($actions)], 'description' => $descriptions[array_rand($descriptions)], 'ip_address' => '127.0.0.1', 'created_at' => now()->subHours(rand(1, 72)), ]); } } }