114 lines
3.7 KiB
PHP
114 lines
3.7 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
|
|
{
|
|
private function checkExistedData($slug, $isSoftDeleted = false)
|
|
{
|
|
$query = AiringProofTheme::withTrashed()->where('slug', $slug);
|
|
|
|
if($isSoftDeleted){
|
|
$query->whereNotNull('deleted_at');
|
|
}
|
|
|
|
return $query->first();
|
|
}
|
|
|
|
public function index(){
|
|
return view('dashboard.airing-proof-themes.index', [
|
|
'title' => "Tema Bukti Tayang"
|
|
]);
|
|
}
|
|
|
|
public function create(){
|
|
return view('dashboard.airing-proof-themes.create', [
|
|
'title' => "Tambah Tema Bukti Tayang"
|
|
]);
|
|
}
|
|
|
|
public function store(AiringProofThemeRequest $request){
|
|
$validatedData = $request->validated();
|
|
|
|
if($this->checkExistedData($validatedData['slug'], true)){
|
|
return redirect()->back()->with('data-exists', $validatedData['slug']);
|
|
}elseif($this->checkExistedData($validatedData['slug'])){
|
|
return redirect()->back()->with('failed-status', 'Tema dengan nama dan tahun tersebut sudah ada.');
|
|
}
|
|
|
|
try{
|
|
AiringProofTheme::create($validatedData);
|
|
return redirect()->back()->with('success-status', 'Berhasil menambahkan tema bukti tayang.');
|
|
}catch(\Exception $e){
|
|
return redirect()->back()->with('failed-status', 'Gagal menambahkan tema bukti tayang.');
|
|
}
|
|
}
|
|
|
|
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()->back()->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)
|
|
{
|
|
$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()->back()->with('success-status', 'Tema berhasil dipulihkan.');
|
|
}
|
|
|
|
return redirect()->back()->with('info-status', 'Tema sudah aktif.');
|
|
}
|
|
|
|
}
|