From be89941651d6005dd2bd5ea68caffd96a1a6a0e1 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Tue, 5 Nov 2024 12:01:55 +0700 Subject: [PATCH] Refactor PermohonanController for consistency and readability Consolidated route method chaining for more concise syntax. Added a status check before updating a permohonan record to ensure correct status transitions. Made minor formatting improvements for better readability. --- app/Http/Controllers/PermohonanController.php | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/PermohonanController.php b/app/Http/Controllers/PermohonanController.php index e2a3da4..b6a43f6 100644 --- a/app/Http/Controllers/PermohonanController.php +++ b/app/Http/Controllers/PermohonanController.php @@ -33,25 +33,20 @@ public function store(PermohonanRequest $request) { - $validate = $request->validated(); if ($validate) { try { // Save to database Permohonan::create($validate); return redirect() - ->route('permohonan.index') - ->with('success', 'Permohonan created successfully'); + ->route('permohonan.index')->with('success', 'Permohonan created successfully'); } catch (Exception $e) { return redirect() - ->route('permohonan.create') - ->with('error', 'Failed to create permohonan' . $e->getMessage()); + ->route('permohonan.create')->with('error', 'Failed to create permohonan' . $e->getMessage()); } } else { return redirect() - ->route('permohonan.create') - ->with('success', 'error naon iye') - ->withInput(); + ->route('permohonan.create')->with('success', 'error naon iye')->withInput(); } } @@ -118,14 +113,15 @@ try { // Update in database $permohonan = Permohonan::find($id); + if ($permohonan->status == 'revisi') { + $validate['status'] = 'order'; + } $permohonan->update($validate); return redirect() - ->route('permohonan.index') - ->with('success', 'Permohonan updated successfully'); + ->route('permohonan.index')->with('success', 'Permohonan updated successfully'); } catch (Exception $e) { return redirect() - ->route('permohonan.edit', $id) - ->with('error', 'Failed to update permohonan'); + ->route('permohonan.edit', $id)->with('error', 'Failed to update permohonan'); } } } @@ -313,11 +309,12 @@ return view('lpj::permohonan.show', compact('permohonan')); } - public function print($id){ + public function print($id) + { $permohonan = Permohonan::find($id); return view('lpj::permohonan.print', compact('permohonan')); -// $pdf = Pdf::loadView('lpj::permohonan.print', compact('permohonan')); - // return $pdf->stream(); + // $pdf = Pdf::loadView('lpj::permohonan.print', compact('permohonan')); + // return $pdf->stream(); } }