112 lines
3.8 KiB
PHP
112 lines
3.8 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' => "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();
|
|
$validatedData['slug'] = Str::slug($validatedData['name']. ' '. $validatedData['year']);
|
|
$validatedData['enhancer_id'] = Auth::id();
|
|
|
|
$existedData = AiringProofTheme::withTrashed()->where('slug', $validatedData['slug'])->first();
|
|
|
|
if($existedData && filled($existedData->deleted_at)){
|
|
return redirect()->back()->with('data-exists', $validatedData['slug']);
|
|
}elseif($existedData){
|
|
return redirect()->back()->with('failed-status', 'Tema dengan nama dan tahun tersebut sudah ada.');
|
|
}
|
|
|
|
$createdTheme = AiringProofTheme::create($validatedData);
|
|
|
|
if($createdTheme){
|
|
return redirect()->back()->with('success-status', 'Berhasil menambahkan tema bukti tayang.');
|
|
}else{
|
|
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();
|
|
$validatedData['slug'] = Str::slug($validatedData['name']. ' '. $validatedData['year']);
|
|
$validatedData['enhancer_id'] = Auth::id();
|
|
|
|
$airingProofTheme = AiringProofTheme::findOrFail(decrypt_id($id));
|
|
$updatedAiringProofTheme = $airingProofTheme->update($validatedData);
|
|
|
|
if($updatedAiringProofTheme){
|
|
return redirect()->back()->with('success-status', 'Berhasil mengubah tema bukti tayang.');
|
|
}else{
|
|
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.');
|
|
}
|
|
|
|
}
|