validate([ 'reason_type' => 'required|string', 'weather_condition' => 'nullable|string', 'delay_date' => 'required|date', 'lost_hours' => 'required|numeric|min:0', 'notes' => 'nullable|string|max:2000', ]); $validated['task_id'] = $task->id; $validated['reported_by'] = $request->user()->id; TaskDelay::create($validated); return back()->with('success', 'Delay logged.'); } public function update(Request $request, Project $project, Task $task, TaskDelay $delay) { $validated = $request->validate([ 'reason_type' => 'sometimes|required|string', 'weather_condition' => 'nullable|string', 'delay_date' => 'sometimes|required|date', 'lost_hours' => 'sometimes|required|numeric|min:0', 'notes' => 'nullable|string|max:2000', ]); // Clear weather_condition if reason is not weather if (isset($validated['reason_type']) && $validated['reason_type'] !== DelayReason::Weather->value) { $validated['weather_condition'] = null; } $delay->update($validated); return back()->with('success', 'Delay updated.'); } public function destroy(Project $project, Task $task, TaskDelay $delay) { $delay->delete(); return back()->with('success', 'Delay removed.'); } }