timeline = $timeline->load(['user', 'updates.admin']); } public function rules(): array { return [ 'updateText' => ['required', 'string', 'min:10'], ]; } public function messages(): array { return [ 'updateText.required' => __('timelines.update_text_required'), 'updateText.min' => __('timelines.update_text_min'), ]; } public function addUpdate(): void { $this->validate(); $update = $this->timeline->updates()->create([ 'admin_id' => auth()->id(), 'update_text' => clean($this->updateText), ]); $this->timeline->user->notify(new TimelineUpdateNotification($update)); AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'create', 'target_type' => 'timeline_update', 'target_id' => $update->id, 'new_values' => $update->toArray(), 'ip_address' => request()->ip(), 'created_at' => now(), ]); $this->updateText = ''; $this->timeline->load(['updates.admin']); session()->flash('success', __('messages.update_added')); } public function editUpdate(int $updateId): void { $update = $this->timeline->updates()->findOrFail($updateId); $this->editingUpdateId = $updateId; $this->updateText = $update->update_text; } public function saveEdit(): void { $this->validate(); $update = $this->timeline->updates()->findOrFail($this->editingUpdateId); $oldText = $update->update_text; $update->update([ 'update_text' => clean($this->updateText), ]); AdminLog::create([ 'admin_id' => auth()->id(), 'action' => 'update', 'target_type' => 'timeline_update', 'target_id' => $update->id, 'old_values' => ['update_text' => $oldText], 'new_values' => ['update_text' => clean($this->updateText)], 'ip_address' => request()->ip(), 'created_at' => now(), ]); $this->editingUpdateId = null; $this->updateText = ''; $this->timeline->load(['updates.admin']); session()->flash('success', __('messages.update_edited')); } public function cancelEdit(): void { $this->editingUpdateId = null; $this->updateText = ''; } }; ?>