diff --git a/app/Http/Controllers/Dashboard/AiringProofThemeController.php b/app/Http/Controllers/Dashboard/AiringProofThemeController.php new file mode 100644 index 0000000..2754e99 --- /dev/null +++ b/app/Http/Controllers/Dashboard/AiringProofThemeController.php @@ -0,0 +1,84 @@ + "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); + } + } +} diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index c9ecdfe..953a0b6 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Dashboard; use App\Http\Controllers\Controller; +use App\Models\AiringProofTheme; use App\Models\Classification; use App\Models\GovernmentAgency; use App\Models\News; @@ -246,4 +247,50 @@ public function news(Request $request){ return response()->json(['error' => 'Unauthorized'], 401); } + + public function airingProofTheme(Request $request){ + if ($request->ajax()) { + + + + $data = AiringProofTheme::all(); + + return DataTables::of($data) + ->addIndexColumn() + ->addColumn('action', function ($data) { + $showUrl = route('dashboard.airing.proof.themes.show', ['id' => encrypt_id($data->id)]); + + $editUrl = route('dashboard.airing.proof.themes.edit', ['id' => encrypt_id($data->id)]); + + $deleteUrl = route('dashboard.airing.proof.themes.destroy', ['id' => encrypt_id($data->id)]); + + $dropdown = '
'; + + return $dropdown; + }) + + ->rawColumns(['action']) + ->make(true); + } + + return response()->json(['error' => 'Unauthorized'], 401); + + } } diff --git a/app/Http/Requests/AiringProofThemeRequest.php b/app/Http/Requests/AiringProofThemeRequest.php new file mode 100644 index 0000000..fa14b79 --- /dev/null +++ b/app/Http/Requests/AiringProofThemeRequest.php @@ -0,0 +1,42 @@ +|string> + */ + public function rules(): array + { + return [ + 'name' => ['required', 'max:100'], + 'year' => ['required', 'max:5'], + 'description' => ['nullable'], + ]; + } + + public function messages(): array + { + return [ + 'name.required' => 'Nama harus diisi.', + 'name.max' => 'Nama tidak boleh lebih dari 100 karakter.', + 'year.required' => 'Tahun harus diisi.', + 'year.max' => 'Tahun tidak boleh lebih dari 5 karakter.', + 'description.nullable' => 'Deskripsi bersifat opsional.', + ]; + } +} diff --git a/app/Models/AiringProofTheme.php b/app/Models/AiringProofTheme.php new file mode 100644 index 0000000..dbfe3bf --- /dev/null +++ b/app/Models/AiringProofTheme.php @@ -0,0 +1,18 @@ +id(); + $table->string('name'); + $table->string('slug'); + $table->string('year'); + $table->text('description')->nullable(); + $table->unsignedBigInteger('enhancer_id'); + $table->foreign('enhancer_id')->references('id')->on('users'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('airing_proof_themes'); + } +}; diff --git a/database/seeders/AiringProofThemeSeeder.php b/database/seeders/AiringProofThemeSeeder.php new file mode 100644 index 0000000..0d7338a --- /dev/null +++ b/database/seeders/AiringProofThemeSeeder.php @@ -0,0 +1,17 @@ + 'airing_proof_themes']) +@include('partials.dashboard.header') + +