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.
This commit is contained in:
Daeng Deni Mardaeni
2024-11-05 12:01:55 +07:00
parent 0113563a40
commit be89941651

View File

@@ -33,25 +33,20 @@
public function store(PermohonanRequest $request) public function store(PermohonanRequest $request)
{ {
$validate = $request->validated(); $validate = $request->validated();
if ($validate) { if ($validate) {
try { try {
// Save to database // Save to database
Permohonan::create($validate); Permohonan::create($validate);
return redirect() return redirect()
->route('permohonan.index') ->route('permohonan.index')->with('success', 'Permohonan created successfully');
->with('success', 'Permohonan created successfully');
} catch (Exception $e) { } catch (Exception $e) {
return redirect() return redirect()
->route('permohonan.create') ->route('permohonan.create')->with('error', 'Failed to create permohonan' . $e->getMessage());
->with('error', 'Failed to create permohonan' . $e->getMessage());
} }
} else { } else {
return redirect() return redirect()
->route('permohonan.create') ->route('permohonan.create')->with('success', 'error naon iye')->withInput();
->with('success', 'error naon iye')
->withInput();
} }
} }
@@ -118,14 +113,15 @@
try { try {
// Update in database // Update in database
$permohonan = Permohonan::find($id); $permohonan = Permohonan::find($id);
if ($permohonan->status == 'revisi') {
$validate['status'] = 'order';
}
$permohonan->update($validate); $permohonan->update($validate);
return redirect() return redirect()
->route('permohonan.index') ->route('permohonan.index')->with('success', 'Permohonan updated successfully');
->with('success', 'Permohonan updated successfully');
} catch (Exception $e) { } catch (Exception $e) {
return redirect() return redirect()
->route('permohonan.edit', $id) ->route('permohonan.edit', $id)->with('error', 'Failed to update permohonan');
->with('error', 'Failed to update permohonan');
} }
} }
} }
@@ -313,11 +309,12 @@
return view('lpj::permohonan.show', compact('permohonan')); return view('lpj::permohonan.show', compact('permohonan'));
} }
public function print($id){ public function print($id)
{
$permohonan = Permohonan::find($id); $permohonan = Permohonan::find($id);
return view('lpj::permohonan.print', compact('permohonan')); return view('lpj::permohonan.print', compact('permohonan'));
// $pdf = Pdf::loadView('lpj::permohonan.print', compact('permohonan')); // $pdf = Pdf::loadView('lpj::permohonan.print', compact('permohonan'));
// return $pdf->stream(); // return $pdf->stream();
} }
} }