diff --git a/app/Helpers/CustomHelper.php b/app/Helpers/CustomHelper.php index 7c1d628..fbd4994 100644 --- a/app/Helpers/CustomHelper.php +++ b/app/Helpers/CustomHelper.php @@ -1,6 +1,7 @@ locale('id')->translatedFormat($format); + } +} diff --git a/app/Http/Controllers/Dashboard/ContentRecapController.php b/app/Http/Controllers/Dashboard/ContentRecapController.php new file mode 100644 index 0000000..c5c9aa9 --- /dev/null +++ b/app/Http/Controllers/Dashboard/ContentRecapController.php @@ -0,0 +1,82 @@ + 'Rekap Konten' + ]); + } + + public function create(){ + return view('dashboard.content-recaps.create', [ + 'title' => 'Tambah Rekap Konten' + ]); + } + + public function store(ContentRecapRequest $request){ + $validatedData = $request->validated(); + $validatedData['enhancer_id'] = Auth::id(); + + $createdContentRecap = ContentRecap::create($validatedData); + + if($createdContentRecap){ + return redirect()->back()->with('success-status', 'Berhasil menambahkan rekap konten.'); + }else{ + return redirect()->back()->with('failed-status', 'Gagal menambahkan rekap konten.'); + } + } + + public function edit($id){ + $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); + + return view('dashboard.content-recaps.edit', [ + 'title' => 'Ubah Rekap Konten', + 'contentRecap' => $contentRecap + ]); + } + + public function update(ContentRecapRequest $request, $id){ + $validatedData = $request->validated(); + $validatedData['enhancer_id'] = Auth::id(); + + $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); + $updatedContentRecap = $contentRecap->update($validatedData); + + if($updatedContentRecap){ + return redirect()->back()->with('success-status', 'Berhasil mengubah rekap konten.'); + }else{ + return redirect()->back()->with('failed-status', 'Gagal mengubah rekap konten.'); + } + + } + + public function show($id){ + $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); + + return view('dashboard.content-recaps.show', [ + 'title' => 'Detail Rekap Konten', + 'contentRecap' => $contentRecap + ]); + } + + public function destroy($id){ + try { + $contentRecap = ContentRecap::findOrFail(decrypt_id($id)); + + $contentRecap->delete(); + + return response()->json(['message' => 'Berhasil menghapus rekap konten.']); + } catch (\Exception $e) { + return response()->json(['message' => 'Gagal menghapus rekap konten.'], 500); + } + } +} diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index 953a0b6..2c64009 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -5,6 +5,7 @@ use App\Http\Controllers\Controller; use App\Models\AiringProofTheme; use App\Models\Classification; +use App\Models\ContentRecap; use App\Models\GovernmentAgency; use App\Models\News; use App\Models\SubClassification; @@ -12,6 +13,7 @@ use Illuminate\Support\Facades\Log; use SebastianBergmann\Type\TrueType; use Yajra\DataTables\DataTables; +use Illuminate\Support\Str; class DatatableController extends Controller { @@ -293,4 +295,57 @@ public function airingProofTheme(Request $request){ return response()->json(['error' => 'Unauthorized'], 401); } + + public function contentRecap(Request $request){ + if ($request->ajax()) { + + $data = ContentRecap::all(); + + return DataTables::of($data) + ->addIndexColumn() + ->addColumn('channel', function ($data){ + return Str::ucfirst($data->channel); + }) + ->addColumn('posted_date', function ($data){ + return idn_date($data->posted_date, 'd F Y'); + }) + ->addColumn('link', function ($data){ + return ''.$data->link.''; + }) + ->addColumn('action', function ($data) { + $showUrl = route('dashboard.content.recaps.show', ['id' => encrypt_id($data->id)]); + + $editUrl = route('dashboard.content.recaps.edit', ['id' => encrypt_id($data->id)]); + + $deleteUrl = route('dashboard.content.recaps.destroy', ['id' => encrypt_id($data->id)]); + + $dropdown = '
'; + + return $dropdown; + }) + + ->rawColumns(['link', 'action']) + ->make(true); + } + + return response()->json(['error' => 'Unauthorized'], 401); + + } } diff --git a/app/Http/Requests/ContentRecapRequest.php b/app/Http/Requests/ContentRecapRequest.php new file mode 100644 index 0000000..9422c41 --- /dev/null +++ b/app/Http/Requests/ContentRecapRequest.php @@ -0,0 +1,48 @@ +|string> + */ + public function rules(): array + { + return [ + 'title' => ['required'], + 'posted_date' => ['required', 'date'], + 'channel'=> ['required', 'in:website,tiktok,youtube,instagram,facebook,twitter,cetak'], + 'link' => ['required', 'url'], + 'classification' => ['required'], + ]; + } + + public function messages() + { + return [ + 'title.required' => 'Judul wajib diisi.', + 'posted_date.required' => 'Tanggal posting wajib diisi.', + 'posted_date.date' => 'Tanggal posting harus berupa format tanggal yang valid.', + 'channel.required' => 'Channel wajib dipilih.', + 'channel.in' => 'Channel harus salah satu dari: website, tiktok, youtube, instagram, facebook, twitter, atau cetak.', + 'link.required' => 'Link wajib diisi.', + 'link.url' => 'Link harus berupa URL yang valid.', + 'classification.required' => 'Klasifikasi wajib diisi.', + ]; + } + +} diff --git a/app/Models/ContentRecap.php b/app/Models/ContentRecap.php new file mode 100644 index 0000000..217f8f8 --- /dev/null +++ b/app/Models/ContentRecap.php @@ -0,0 +1,24 @@ +belongsTo(User::class, 'enhancer_id', 'id'); + } +} diff --git a/database/migrations/2025_02_28_010029_create_content_recaps_table.php b/database/migrations/2025_02_28_010029_create_content_recaps_table.php new file mode 100644 index 0000000..9bf3fd4 --- /dev/null +++ b/database/migrations/2025_02_28_010029_create_content_recaps_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('title'); + $table->date('posted_date'); + $table->enum('channel', ['website', 'tiktok', 'youtube', 'instagram', 'facebook', 'twitter', 'cetak']); + $table->string('link'); + $table->string('classification'); + $table->unsignedBigInteger('enhancer_id'); + $table->foreign('enhancer_id')->references('id')->on('users'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('content_recaps'); + } +}; diff --git a/database/seeders/ContentRecapSeeder.php b/database/seeders/ContentRecapSeeder.php new file mode 100644 index 0000000..67cddbc --- /dev/null +++ b/database/seeders/ContentRecapSeeder.php @@ -0,0 +1,17 @@ + 'content_recaps']) +@include('partials.dashboard.header') + +