apiService = $apiService; } public function mount($id) { // Check role-based access $userInfo = Session::get('userInfo'); if (!$userInfo || $userInfo['role'] != 1) { return redirect()->route('404'); } $this->id = $id; try { $response = $this->apiService->get("topUp/{$id}"); if ($response && isset($response['data'])) { $this->userInfo = $response['data']; $this->mounted = true; Log::info('Top-up data loaded', ['source' => 'TopUpView']); } } catch (\Exception $e) { Session::flash('error', 'Something went wrong loading data: ' . $e->getMessage()); Log::error('Failed to load top-up data', ['error' => $e->getMessage(), 'source' => 'TopUpView']); if ($e->getCode() == 404) { return redirect()->route('404'); } $this->mounted = false; } } public function delete() { try { $response = $this->apiService->delete("topUp/{$this->userInfo['topup_uuid']}"); if ($response && isset($response['status']) && $response['status'] === 200) { Session::flash('success', 'Record was successfully deleted.'); Log::info('Top-up deleted successfully', ['source' => 'TopUpView']); return redirect()->route('top-up'); } } catch (\Exception $e) { Session::flash('error', 'Something went wrong deleting record: ' . $e->getMessage()); Log::error('Failed to delete top-up', ['error' => $e->getMessage(), 'source' => 'TopUpView']); } } public function render() { return view('livewire.top-up.view')->layout('layouts.app', ['title' => 'View Top-Up']); } }