skl/app/Http/Controllers/RefHistoryKegiatanControlle...

68 lines
2.6 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\HistoryKegiatanRequest;
use App\Http\Requests\RefHistoryKegiatanRequest;
use App\Models\RefHistoryKegiatan;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Inertia\Inertia;
class RefHistoryKegiatanController extends Controller
{
public function index()
{
try {
$refhistorykegiatan = RefHistoryKegiatan::latest()->get();
return Inertia::render('admin/kegiatan/index_refhistory_kegiatan', ['refhistorykegiatan' => $refhistorykegiatan]);
} catch (\Exception $e) {
Log::error('Error fetching Ref History Kegiatan: ' . $e->getMessage());
return back()->with('error', 'Something went wrong.');
}
}
public function store(RefHistoryKegiatanRequest $request)
{
try {
$refhistorykegiatan = RefHistoryKegiatan::withTrashed()
->where('NamaHistoryKegiatan', $request->NamaHistoryKegiatan)
->first();
if ($refhistorykegiatan) {
$refhistorykegiatan->restore();
return redirect()->route('admin.refhistorykegiatan.index')->with('success', 'Ref History Kegiatan berhasil dikembalikan.');
}
RefHistoryKegiatan::create($request->validated());
return redirect()->route('admin.refhistorykegiatan.index')->with('success', 'Ref History Kegiatan berhasil dibuat.');
} catch (\Exception $e) {
Log::error('Error creating Ref History Kegiatan: ' . $e->getMessage());
return back()->with('error', 'Something went wrong.');
}
}
public function update(RefHistoryKegiatanRequest $request, RefHistoryKegiatan $refhistorykegiatan)
{
try {
$refhistorykegiatan->update($request->validated());
return redirect()->route('admin.refhistorykegiatan.index')->with('success', 'Ref History Kegiatan berhasil diperbarui.');
} catch (\Exception $e) {
Log::error('Error updating Ref History Kegiatan: ' . $e->getMessage());
return back()->with('error', 'Something went wrong.');
}
}
public function destroy(RefHistoryKegiatan $refhistorykegiatan)
{
try {
$refhistorykegiatan->delete();
return redirect()->route('admin.refhistorykegiatan.index')->with('success', 'Ref History Kegiatan berhasil dihapus.');
} catch (\Exception $e) {
Log::error('Error deleting Ref History Kegiatan: ' . $e->getMessage());
return back()->with('error', 'Something went wrong.');
}
}
}