patchFileId = $patchFileId; $patchFile = TabPatchFile::where('fid', $this->patchFileId)->first(); $this->patchFile = TabPatchFile::where('fid', $this->patchFileId)->first(); $this->isOpenEditCode = true; $this->dbCode = base64_decode( $this->patchFile); // $this->gitCode = $this->getFileContentFromGit(); } public function closeModal() { $this->isOpenEditCode = false; } public function updateCode() { } private function getFileContentFromGit($filePath, $commit) { $token = env('GITLAB_API_TOKEN'); $client = new Client([ 'base_uri' => 'https://idemo.netbay.co.th/gitlab/api/v4/', 'headers' => [ 'Authorization' => "Bearer $token", 'Accept' => 'application/json', ], 'verify' => false, ]); try { $response = $client->get("projects/$this->selectedProject/repository/files/" . urlencode($filePath) . "/raw", [ 'query' => ['ref' => $commit] ]); $statusCode = $response->getStatusCode(); $content = $response->getBody()->getContents(); if ($statusCode == 200) { return $content; } else { throw new \Exception("Failed to fetch file. Status code: $statusCode"); } } catch (RequestException $e) { throw $e; } catch (\Exception $e) { throw $e; } } public function render() { return view('livewire.pages.patch.modal-edit-code'); } }