From 61f3f862c5c6b4de0e801b11c404892d52073a3d Mon Sep 17 00:00:00 2001 From: myuqinurrohman Date: Fri, 28 Feb 2025 09:06:03 +0700 Subject: [PATCH] feat: content recap --- app/Helpers/CustomHelper.php | 8 ++ .../Dashboard/ContentRecapController.php | 82 +++++++++++++++ .../Dashboard/DatatableController.php | 55 +++++++++++ app/Http/Requests/ContentRecapRequest.php | 48 +++++++++ app/Models/ContentRecap.php | 24 +++++ ..._28_010029_create_content_recaps_table.php | 34 +++++++ database/seeders/ContentRecapSeeder.php | 17 ++++ .../dashboard/content-recaps/create.blade.php | 98 ++++++++++++++++++ .../dashboard/content-recaps/edit.blade.php | 99 +++++++++++++++++++ .../dashboard/content-recaps/index.blade.php | 64 ++++++++++++ .../dashboard/content-recaps/show.blade.php | 78 +++++++++++++++ .../views/partials/app/datatable.blade.php | 26 +++++ .../partials/dashboard/sidebar.blade.php | 2 +- routes/web.php | 15 +++ 14 files changed, 649 insertions(+), 1 deletion(-) create mode 100644 app/Http/Controllers/Dashboard/ContentRecapController.php create mode 100644 app/Http/Requests/ContentRecapRequest.php create mode 100644 app/Models/ContentRecap.php create mode 100644 database/migrations/2025_02_28_010029_create_content_recaps_table.php create mode 100644 database/seeders/ContentRecapSeeder.php create mode 100644 resources/views/dashboard/content-recaps/create.blade.php create mode 100644 resources/views/dashboard/content-recaps/edit.blade.php create mode 100644 resources/views/dashboard/content-recaps/index.blade.php create mode 100644 resources/views/dashboard/content-recaps/show.blade.php 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') + +
+
+
+
+
+
+
+
+
{{$title}}
+
+ @foreach ($errors->all() as $item) + {{$item}} + @endforeach +
+ @csrf +
+
+
+ +
+ +
+ @error('title') + {{$message}} + @enderror +
+
+
+
+ +
+ +
+ @error('link') + {{$message}} + @enderror +
+
+
+
+ +
+ +
+ @error('classification') + {{$message}} + @enderror +
+
+
+
+ +
+ +
+ @error('posted_date') + {{$message}} + @enderror +
+
+
+
+ +
+ +
+
+
+
+
+
+ Kembali + +
+
+
+
+
+
+
+
+
+
+
+ +@include('partials.dashboard.footer', ['rich_editor' => true]) diff --git a/resources/views/dashboard/content-recaps/edit.blade.php b/resources/views/dashboard/content-recaps/edit.blade.php new file mode 100644 index 0000000..dc1ebf7 --- /dev/null +++ b/resources/views/dashboard/content-recaps/edit.blade.php @@ -0,0 +1,99 @@ +@include('partials.dashboard.head') +@include('partials.dashboard.sidebar', ['page' => 'content_recaps']) +@include('partials.dashboard.header') + +
+
+
+
+
+
+
+
+
{{$title}}
+
+ @foreach ($errors->all() as $item) + {{$item}} + @endforeach +
+ @csrf + @method('put') +
+
+
+ +
+ +
+ @error('title') + {{$message}} + @enderror +
+
+
+
+ +
+ +
+ @error('link') + {{$message}} + @enderror +
+
+
+
+ +
+ +
+ @error('classification') + {{$message}} + @enderror +
+
+
+
+ +
+ +
+ @error('posted_date') + {{$message}} + @enderror +
+
+
+
+ +
+ +
+
+
+
+
+
+ Kembali + +
+
+
+
+
+
+
+
+
+
+
+ +@include('partials.dashboard.footer', ['rich_editor' => true]) diff --git a/resources/views/dashboard/content-recaps/index.blade.php b/resources/views/dashboard/content-recaps/index.blade.php new file mode 100644 index 0000000..2627ac3 --- /dev/null +++ b/resources/views/dashboard/content-recaps/index.blade.php @@ -0,0 +1,64 @@ +@include('partials.dashboard.head') +@include('partials.dashboard.sidebar', ['page' => 'content_recaps']) +@include('partials.dashboard.header') + +
+
+
+
+
+
+
+

{{$title}}

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+ + + + + + + + + + + + +
NoJudulKanalTanggal PostingKlasifikasiLink
+
+
+
+
+
+
+
+
+ +@include('partials.dashboard.footer' ,['datatable' => 'content_recap']) diff --git a/resources/views/dashboard/content-recaps/show.blade.php b/resources/views/dashboard/content-recaps/show.blade.php new file mode 100644 index 0000000..95cc6b3 --- /dev/null +++ b/resources/views/dashboard/content-recaps/show.blade.php @@ -0,0 +1,78 @@ +@include('partials.dashboard.head') +@include('partials.dashboard.sidebar', ['page' => 'content_recaps']) +@include('partials.dashboard.header') + +
+
+
+
+
+
+
+
+
{{$title}}
+
+ @foreach ($errors->all() as $item) + {{$item}} + @endforeach +
+ @csrf +
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+
+
+
+
+ Kembali + Ubah +
+
+
+
+
+
+
+
+
+
+
+ +@include('partials.dashboard.footer', ['rich_editor' => true]) diff --git a/resources/views/partials/app/datatable.blade.php b/resources/views/partials/app/datatable.blade.php index 0022122..8c31290 100644 --- a/resources/views/partials/app/datatable.blade.php +++ b/resources/views/partials/app/datatable.blade.php @@ -137,3 +137,29 @@ }); @endif + +@if ($datatable === 'content_recap') + +@endif diff --git a/resources/views/partials/dashboard/sidebar.blade.php b/resources/views/partials/dashboard/sidebar.blade.php index d43c642..9d53eb4 100644 --- a/resources/views/partials/dashboard/sidebar.blade.php +++ b/resources/views/partials/dashboard/sidebar.blade.php @@ -139,7 +139,7 @@
Monitoring
  • - + Rekap Konten diff --git a/routes/web.php b/routes/web.php index 26a9c41..51faf2b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,6 +3,7 @@ use App\Http\Controllers\AuthController; use App\Http\Controllers\Dashboard\AiringProofThemeController; use App\Http\Controllers\Dashboard\ClassificationController; +use App\Http\Controllers\Dashboard\ContentRecapController; use App\Http\Controllers\Dashboard\DatatableController; use App\Http\Controllers\Dashboard\GovernmentAgencyController; use App\Http\Controllers\Dashboard\NewsController; @@ -111,5 +112,19 @@ Route::put('/', 'update')->name('update'); }); }); + + Route::prefix('content-recaps')->name('content.recaps.')->group(function(){ + Route::controller(ContentRecapController::class)->group(function(){ + Route::get('/', 'index')->name('index'); + Route::get('/create', 'create')->name('create'); + Route::post('/', 'store')->name('store'); + Route::get('/{id}/show', 'show')->name('show'); + Route::get('/{id}/edit', 'edit')->name('edit'); + Route::put('/{id}', 'update')->name('update'); + Route::delete('/{id}', 'destroy')->name('destroy'); + }); + + Route::get('/data', [DatatableController::class, 'contentRecap'])->name('data'); + }); }); });