85 lines
2.8 KiB
PHP
85 lines
2.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();
|
|
|
|
$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);
|
|
}
|
|
}
|
|
}
|