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:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user