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 = ''; } }; ?>
{{ __('timelines.back_to_timelines') }}
{{-- Timeline Header --}}
{{ $timeline->case_name }} @if($timeline->case_reference)
{{ __('timelines.reference') }}: {{ $timeline->case_reference }}
@endif
{{ $timeline->status->label() }}
{{ $timeline->user->full_name }}
{{ $timeline->user->email }}
{{ __('timelines.created') }}: {{ $timeline->created_at->format('Y-m-d') }}
{{-- Flash Messages --}} @if(session('success'))
{{ session('success') }}
@endif {{-- Add Update Form --}}
{{ __('timelines.add_update') }}
{{ __('timelines.update_text') }} * {{ __('timelines.update_min_chars') }}
@if($editingUpdateId) {{ __('timelines.save_edit') }} {{ __('timelines.cancel') }} @else {{ __('timelines.add_update_button') }} @endif
{{-- Timeline Updates --}}
{{ __('timelines.updates_history') }} @if($timeline->updates->isEmpty())
{{ __('timelines.no_updates') }}
@else
{{-- Timeline line --}}
@foreach($timeline->updates as $update)
{{-- Timeline dot --}}
{{-- Update content --}}
{{ $update->admin->full_name }} {{ $update->created_at->format('Y-m-d H:i') }} @if($update->updated_at->gt($update->created_at)) {{ __('timelines.edited') }} @endif
@if(!$editingUpdateId) {{ __('timelines.edit') }} @endif
{!! $update->update_text !!}
@endforeach
@endif