hasAnyRole(['travel_approver', 'administrator']), 403); $this->travelRequest = TravelRequest::with([ 'user', 'journeys', 'costCodes', 'approvals.step', 'approvals.approver', ])->findOrFail($id); $this->pendingApproval = $this->travelRequest->approvals() ->where('status', \App\Enums\ApprovalStatus::Pending->value) ->with('step') ->first(); } public function approve(): void { abort_unless($this->pendingApproval, 403); app(ApprovalService::class)->approve($this->pendingApproval, Auth::user(), $this->comments ?: null); session()->flash('success', 'Request approved successfully.'); $this->redirect(route('dashboard'), navigate: true); } public function reject(): void { $this->validate(['comments' => ['required', 'string', 'min:5']], [ 'comments.required' => 'Please provide a reason for rejection.', 'comments.min' => 'Rejection reason must be at least 5 characters.', ]); abort_unless($this->pendingApproval, 403); app(ApprovalService::class)->reject($this->pendingApproval, Auth::user(), $this->comments); session()->flash('success', 'Request rejected.'); $this->redirect(route('dashboard'), navigate: true); } public function render(): mixed { return view('livewire.travel-request.approve'); } } ?>