128 lines
4.2 KiB
PHP
128 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Dashboard;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\AiringProofThemeRequest;
|
|
use App\Models\AiringProofTheme;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class AiringProofThemeController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
return view('dashboard.airing-proof-themes.index', [
|
|
'title' => 'Data Tema Bukti Tayang',
|
|
]);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
return view('dashboard.airing-proof-themes.create', [
|
|
'title' => 'Buat Tema Bukti Tayang Baru',
|
|
]);
|
|
}
|
|
|
|
public function store(AiringProofThemeRequest $request)
|
|
{
|
|
$validatedData = $request->validated();
|
|
|
|
try {
|
|
$slug = $validatedData['slug'];
|
|
$existing = AiringProofTheme::withTrashed()
|
|
->where('slug', $slug)
|
|
->first();
|
|
|
|
if ($existing?->trashed()) {
|
|
return redirect()->back()->with('data-exists', $slug);
|
|
} elseif ($existing) {
|
|
return redirect()->back()
|
|
->with('failed-status', 'Tema dengan nama dan tahun tersebut sudah ada.');
|
|
}
|
|
|
|
$createdAiringProofTheme = AiringProofTheme::create($validatedData);
|
|
} catch (\Exception $e) {
|
|
Log::error('Airing Proof Themes (store): '.$e);
|
|
|
|
return redirect()->back()->with('failed-status', 'Gagal membuat tema bukti tayang baru.');
|
|
}
|
|
|
|
return redirect()->route('dashboard.airing.proof.themes.index')->with('success-status', 'Berhasil membuat tema bukti tayang baru.')->with('new_data', encrypt_id($createdAiringProofTheme->id));
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$airingProofTheme = AiringProofTheme::findOrFail(decrypt_id($id));
|
|
|
|
return view('dashboard.airing-proof-themes.edit', [
|
|
'title' => 'Ubah Tema Bukti Tayang',
|
|
'airingProofTheme' => $airingProofTheme,
|
|
]);
|
|
}
|
|
|
|
public function update(AiringProofThemeRequest $request, $id)
|
|
{
|
|
$validatedData = $request->validated();
|
|
|
|
try {
|
|
$airingProofTheme = AiringProofTheme::findOrFail(decrypt_id($id));
|
|
$airingProofTheme->update($validatedData);
|
|
} catch (\Exception $e) {
|
|
Log::error('Airing Proof Themes (update): '.$e);
|
|
|
|
return redirect()->back()->with('failed-status', 'Gagal mengubah tema bukti tayang.');
|
|
}
|
|
|
|
return redirect()->route('dashboard.airing.proof.themes.show', ['id' => encrypt_id($airingProofTheme->id)])->with('success-status', 'Berhasil mengubah tema bukti tayang.');
|
|
}
|
|
|
|
public function show($id)
|
|
{
|
|
$airingProofTheme = AiringProofTheme::findOrFail(decrypt_id($id));
|
|
|
|
return view('dashboard.airing-proof-themes.show', [
|
|
'title' => 'Detail Tema Bukti Tayang',
|
|
'airingProofTheme' => $airingProofTheme,
|
|
]);
|
|
}
|
|
|
|
public function destroy($id)
|
|
{
|
|
try {
|
|
$airingProofTheme = AiringProofTheme::findOrFail(decrypt_id($id));
|
|
$airingProofTheme->delete();
|
|
} catch (\Exception $e) {
|
|
Log::error('Airing Proof Themes (destroy): '.$e);
|
|
|
|
return response()->json(['message' => 'Gagal menghapus tema bukti tayang.'], 500);
|
|
}
|
|
|
|
return response()->json(['message' => 'Berhasil menghapus tema bukti tayang.']);
|
|
}
|
|
|
|
public function restore($slug)
|
|
{
|
|
try {
|
|
$airingProofTheme = AiringProofTheme::withTrashed()
|
|
->where('slug', $slug)
|
|
->first();
|
|
|
|
if (! $airingProofTheme) {
|
|
return redirect()->back()->with('failed-status', 'Tema tidak ditemukan.');
|
|
}
|
|
|
|
if (filled($airingProofTheme->deleted_at)) {
|
|
$airingProofTheme->restore();
|
|
|
|
return redirect()->route('dashboard.airing.proof.themes.index')->with('success-status', 'Tema berhasil dipulihkan.');
|
|
}
|
|
} catch (\Exception $e) {
|
|
Log::error('Airing Proof Themes (restore): '.$e);
|
|
|
|
return redirect()->back()->with('failed-status', 'Proses pemulihan gagal.');
|
|
}
|
|
|
|
return redirect()->back()->with('info-status', 'Tema sudah aktif.');
|
|
}
|
|
}
|