116 lines
3.9 KiB
PHP
116 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Dashboard;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\AiringProofThemeRequest;
|
|
use App\Models\AiringProofTheme;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Str;
|
|
|
|
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{
|
|
$existing = AiringProofTheme::withTrashed()
|
|
->where('slug', $validatedData['slug'])
|
|
->first();
|
|
|
|
if ($existing?->trashed()) {
|
|
return redirect()->back()->with('data-exists', $validatedData['slug']);
|
|
} elseif ($existing) {
|
|
return redirect()->back()
|
|
->with('failed-status', 'Tema dengan nama dan tahun tersebut sudah ada.');
|
|
}
|
|
|
|
$createdAiringProofTheme = AiringProofTheme::create($validatedData);
|
|
|
|
return redirect()->route('dashboard.airing.proof.themes.index')->with('success-status', 'Berhasil membuat tema bukti tayang baru.')
|
|
->with('new_data', encrypt_id($createdAiringProofTheme->id));
|
|
}catch(\Exception $e){
|
|
return redirect()->back()->with('failed-status', 'Gagal membuat tema bukti tayang baru.');
|
|
}
|
|
}
|
|
|
|
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);
|
|
|
|
return redirect()->route('dashboard.airing.proof.themes.show', ['id' => encrypt_id($airingProofTheme->id)])->with('success-status', 'Berhasil mengubah tema bukti tayang.');
|
|
}catch(\Exception $e){
|
|
return redirect()->back()->with('failed-status', 'Gagal 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();
|
|
|
|
return response()->json(['message' => 'Berhasil menghapus tema bukti tayang.']);
|
|
} catch (\Exception $e) {
|
|
return response()->json(['message' => 'Gagal menghapus tema bukti tayang.'], 500);
|
|
}
|
|
}
|
|
|
|
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.');
|
|
}
|
|
|
|
return redirect()->back()->with('info-status', 'Tema sudah aktif.');
|
|
}catch(\Exception $e){
|
|
return redirect()->back()->with('failed-status', 'Proses pemulihan gagal.');
|
|
}
|
|
}
|
|
|
|
}
|