From 54e82c61a792e689390a949463921dc10ac497d3 Mon Sep 17 00:00:00 2001 From: E31232303evimr <158023512+E31232303evimr@users.noreply.github.com> Date: Mon, 16 Mar 2026 09:13:58 +0700 Subject: [PATCH] user-artikel final done --- .../Admin/ArtikelBudidayaController.php | 82 ++- app/Models/BudidayaSub.php | 23 + app/Models/InformasiBudidaya.php | 5 + ...03_16_010621_create_budidaya_sub_table.php | 29 + .../admin/artikel-budidaya/create.blade.php | 92 ++- .../admin/artikel-budidaya/edit.blade.php | 131 +++- .../views/user/artikel/budidaya.blade.php | 468 +++++++++++-- .../user/artikel/detail-budidaya.blade.php | 640 ++++++++++++++++-- .../artikel/detail-hama-penyakit.blade.php | 546 +++++++++++++-- .../user/artikel/hama-penyakit.blade.php | 488 ++++++++++--- 10 files changed, 2126 insertions(+), 378 deletions(-) create mode 100644 app/Models/BudidayaSub.php create mode 100644 database/migrations/2026_03_16_010621_create_budidaya_sub_table.php diff --git a/app/Http/Controllers/Admin/ArtikelBudidayaController.php b/app/Http/Controllers/Admin/ArtikelBudidayaController.php index 0180964..71b20ee 100644 --- a/app/Http/Controllers/Admin/ArtikelBudidayaController.php +++ b/app/Http/Controllers/Admin/ArtikelBudidayaController.php @@ -4,6 +4,7 @@ use App\Http\Controllers\Controller; use App\Models\InformasiBudidaya; +use App\Models\BudidayaSub; use Illuminate\Http\Request; use Illuminate\Support\Str; @@ -25,12 +26,15 @@ public function store(Request $request) $validated = $request->validate([ 'judul' => 'required|string|max:200', 'deskripsi_singkat' => 'nullable|string', - 'konten' => 'required|string', + 'konten' => 'nullable|string', 'gambar_utama' => 'nullable|image|max:2048', 'galeri_gambar.*' => 'nullable|image|max:2048', 'file_pdf' => 'nullable|mimes:pdf|max:5120', 'tags' => 'nullable|string', 'is_published' => 'boolean', + 'sub_judul.*' => 'nullable|string|max:200', + 'sub_konten.*' => 'nullable|string', + 'sub_gambar.*' => 'nullable|image|max:2048', ]); $validated['slug'] = Str::slug($request->judul); @@ -45,45 +49,68 @@ public function store(Request $request) $validated['file_pdf'] = $request->file('file_pdf')->store('budidaya/pdf', 'public'); } - // Handle galeri gambar if ($request->hasFile('galeri_gambar')) { $galeri = []; foreach ($request->file('galeri_gambar') as $foto) { $galeri[] = $foto->store('budidaya/galeri', 'public'); } - $validated['galeri_gambar'] = $galeri; // otomatis di-cast ke JSON oleh model + $validated['galeri_gambar'] = $galeri; } - // Handle tags $tagsDecoded = json_decode($request->tags, true); $validated['tags'] = (!empty($tagsDecoded)) ? $tagsDecoded : null; if ($validated['is_published']) { $validated['published_at'] = now(); } - - InformasiBudidaya::create($validated); + + $artikel = InformasiBudidaya::create($validated); + + // Handle sub-bab + if ($request->has('sub_judul')) { + foreach ($request->sub_judul as $index => $judul) { + if (!empty($judul)) { + $subData = [ + 'id_artikel' => $artikel->id, + 'judul_sub' => $judul, + 'konten' => $request->sub_konten[$index] ?? null, + 'urutan' => $index + 1, + ]; + + if ($request->hasFile("sub_gambar.$index")) { + $path = $request->file("sub_gambar.$index")->store('budidaya/sub', 'public'); + $subData['gambar'] = $path; + } + + BudidayaSub::create($subData); + } + } + } return redirect()->route('admin.artikel-budidaya.index') ->with('success', 'Artikel budidaya berhasil ditambahkan!'); -} + } public function edit(InformasiBudidaya $artikelBudidaya) { + $artikelBudidaya->load('subBab'); return view('admin.artikel-budidaya.edit', compact('artikelBudidaya')); } public function update(Request $request, InformasiBudidaya $artikelBudidaya) { $validated = $request->validate([ - 'judul' => 'required|string|max:200', - 'deskripsi_singkat'=> 'nullable|string', - 'konten' => 'required|string', - 'gambar_utama' => 'nullable|image|max:2048', - 'galeri_gambar.*' => 'nullable|image|max:2048', - 'file_pdf' => 'nullable|mimes:pdf|max:5120', - 'tags' => 'nullable|string', - 'is_published' => 'boolean', + 'judul' => 'required|string|max:200', + 'deskripsi_singkat' => 'nullable|string', + 'konten' => 'nullable|string', + 'gambar_utama' => 'nullable|image|max:2048', + 'galeri_gambar.*' => 'nullable|image|max:2048', + 'file_pdf' => 'nullable|mimes:pdf|max:5120', + 'tags' => 'nullable|string', + 'is_published' => 'boolean', + 'sub_judul.*' => 'nullable|string|max:200', + 'sub_konten.*' => 'nullable|string', + 'sub_gambar.*' => 'nullable|image|max:2048', ]); $validated['slug'] = Str::slug($request->judul); @@ -97,7 +124,6 @@ public function update(Request $request, InformasiBudidaya $artikelBudidaya) $validated['file_pdf'] = $request->file('file_pdf')->store('budidaya/pdf', 'public'); } - // Handle galeri gambar if ($request->hasFile('galeri_gambar')) { $galeri = []; foreach ($request->file('galeri_gambar') as $foto) { @@ -106,7 +132,6 @@ public function update(Request $request, InformasiBudidaya $artikelBudidaya) $validated['galeri_gambar'] = $galeri; } - // Handle tags $tagsDecoded = json_decode($request->tags, true); $validated['tags'] = (!empty($tagsDecoded)) ? $tagsDecoded : null; @@ -116,6 +141,29 @@ public function update(Request $request, InformasiBudidaya $artikelBudidaya) $artikelBudidaya->update($validated); + // Hapus sub-bab lama & simpan yang baru + $artikelBudidaya->subBab()->delete(); + + if ($request->has('sub_judul')) { + foreach ($request->sub_judul as $index => $judul) { + if (!empty($judul)) { + $subData = [ + 'id_artikel' => $artikelBudidaya->id, + 'judul_sub' => $judul, + 'konten' => $request->sub_konten[$index] ?? null, + 'urutan' => $index + 1, + ]; + + if ($request->hasFile("sub_gambar.$index")) { + $path = $request->file("sub_gambar.$index")->store('budidaya/sub', 'public'); + $subData['gambar'] = $path; + } + + BudidayaSub::create($subData); + } + } + } + return redirect()->route('admin.artikel-budidaya.index') ->with('success', 'Artikel budidaya berhasil diupdate!'); } diff --git a/app/Models/BudidayaSub.php b/app/Models/BudidayaSub.php new file mode 100644 index 0000000..b7b5544 --- /dev/null +++ b/app/Models/BudidayaSub.php @@ -0,0 +1,23 @@ +belongsTo(InformasiBudidaya::class, 'id_artikel', 'id'); + } +} \ No newline at end of file diff --git a/app/Models/InformasiBudidaya.php b/app/Models/InformasiBudidaya.php index 2d64301..aa338a8 100644 --- a/app/Models/InformasiBudidaya.php +++ b/app/Models/InformasiBudidaya.php @@ -41,4 +41,9 @@ public function scopePublished($query) { return $query->where('is_published', true); } + + public function subBab() + { + return $this->hasMany(BudidayaSub::class, 'id_artikel', 'id')->orderBy('urutan'); + } } \ No newline at end of file diff --git a/database/migrations/2026_03_16_010621_create_budidaya_sub_table.php b/database/migrations/2026_03_16_010621_create_budidaya_sub_table.php new file mode 100644 index 0000000..29292c5 --- /dev/null +++ b/database/migrations/2026_03_16_010621_create_budidaya_sub_table.php @@ -0,0 +1,29 @@ +id(); + $table->foreignId('id_artikel')->constrained('informasi_budidaya')->onDelete('cascade'); + $table->string('judul_sub'); + $table->longText('konten')->nullable(); + $table->string('gambar')->nullable(); + $table->integer('urutan')->default(0); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('budidaya_sub'); + } +}; diff --git a/resources/views/admin/artikel-budidaya/create.blade.php b/resources/views/admin/artikel-budidaya/create.blade.php index 66e0d38..d84ce68 100644 --- a/resources/views/admin/artikel-budidaya/create.blade.php +++ b/resources/views/admin/artikel-budidaya/create.blade.php @@ -12,10 +12,10 @@
- + + placeholder="Contoh: Persiapan Lahan, Penanaman, dll..."> @error('judul')

{{ $message }}

@enderror
@@ -24,22 +24,13 @@ class="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:rin -
- - -
- - - @error('konten')

{{ $message }}

@enderror + placeholder="Ringkasan singkat tentang bab ini...">{{ old('deskripsi_singkat') }}
- +

Format: JPG, PNG. Maks 2MB

@@ -55,8 +46,7 @@ class="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:rin
-
-
+
@@ -64,12 +54,26 @@ class="w-full mt-2 px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focu
- +
- - -

Bisa pilih beberapa foto sekaligus. Format: JPG, PNG. Maks 2MB per foto

+
+
+ +

Tambahkan sub-bab untuk artikel ini

+
+ +
+ +
+ +
+ +
+

Belum ada sub-bab. Klik tombol di atas untuk menambahkan.

+
@@ -96,6 +100,53 @@ class="w-5 h-5 text-green-600 rounded focus:ring-green-500"> @push('scripts') - @endpush \ No newline at end of file diff --git a/resources/views/admin/artikel-budidaya/edit.blade.php b/resources/views/admin/artikel-budidaya/edit.blade.php index 5ba197b..6fbc89f 100644 --- a/resources/views/admin/artikel-budidaya/edit.blade.php +++ b/resources/views/admin/artikel-budidaya/edit.blade.php @@ -13,7 +13,7 @@
- + @error('judul')

{{ $message }}

@enderror @@ -26,24 +26,16 @@ class="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:rin class="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:ring-green-500 focus:border-transparent">{{ old('deskripsi_singkat', $artikelBudidaya->deskripsi_singkat) }}
- -
- - - @error('konten')

{{ $message }}

@enderror -
- - +
- + @if($artikelBudidaya->gambar_utama) @endif -

Kosongkan jika tidak ingin mengubah gambar

+

Kosongkan jika tidak ingin mengubah

@@ -52,36 +44,74 @@ class="w-full px-4 py-3 border border-gray-300 rounded-xl focus:ring-2 focus:rin @endif -

Kosongkan jika tidak ingin mengubah PDF

+

Kosongkan jika tidak ingin mengubah

-
-
+
-

Tekan Enter atau koma untuk menambah tag

- +
- - @if($artikelBudidaya->galeri_gambar) -
- @foreach($artikelBudidaya->galeri_gambar as $foto) - - @endforeach +
+
+ +

Edit atau tambah sub-bab

+ +
+ +
+ @foreach($artikelBudidaya->subBab as $i => $sub) +
+
+

Sub-bab {{ $i + 1 }}

+ +
+
+ + +
+
+ + +
+
+ + @if($sub->gambar) + + @endif + +

Kosongkan jika tidak ingin mengubah

+
+
+ @endforeach +
+ + @if($artikelBudidaya->subBab->isEmpty()) +
+

Belum ada sub-bab. Klik tombol di atas untuk menambahkan.

+
+ @else + @endif - -

Upload foto baru akan menggantikan galeri yang lama

+
is_published) ? 'checked' : '' }} @@ -106,11 +136,55 @@ class="w-5 h-5 text-green-600 rounded focus:ring-green-500"> @push('scripts') @endpush \ No newline at end of file diff --git a/resources/views/user/artikel/budidaya.blade.php b/resources/views/user/artikel/budidaya.blade.php index 626ea95..1417050 100644 --- a/resources/views/user/artikel/budidaya.blade.php +++ b/resources/views/user/artikel/budidaya.blade.php @@ -1,89 +1,427 @@ @extends('layouts.user-app') -@section('page-title', '🌱 Artikel Budidaya') +@section('page-title', 'Artikel Budidaya') @section('page-subtitle', 'Informasi seputar budidaya tanaman kopi') +@push('styles') + +@endpush + @section('content') - -
-
-
- 🔍 - +
+ + {{-- ── Search Bar ── --}} +
+
+ + + + + + +
+
+ + + + {{ $artikels->total() }} Artikel
-
- -@if($artikels->count() > 0) -
- @foreach($artikels as $artikel) - - -
- @if($artikel->gambar_utama) - {{ $artikel->judul }} - @else -
- 🌱 -
- @endif -
+ {{-- ── Grid Artikel ── --}} + @if($artikels->count() > 0) - -
- - @if($artikel->tags) -
- @foreach(array_slice($artikel->tags, 0, 2) as $tag) - {{ $tag }} - @endforeach -
- @endif +
- -
{{ $artikels->links() }}
+ {{-- Body --}} +
-@else -
- 🌱 -

Belum ada artikel budidaya

-

Artikel akan segera tersedia

-
-@endif + {{-- Tags --}} + @if($artikel->tags) +
+ @foreach(array_slice($artikel->tags, 0, 2) as $tag) + {{ $tag }} + @endforeach +
+ @endif + + {{-- Judul --}} +

{{ $artikel->judul }}

+ + {{-- Excerpt --}} + @if($artikel->deskripsi_singkat) +

{{ $artikel->deskripsi_singkat }}

+ @endif + + {{-- Footer --}} + + +
+ + @endforeach +
+ + {{-- No result pesan --}} +
+ + + + Artikel tidak ditemukan +
+ + {{-- Pagination --}} +
+ {{ $artikels->links() }} +
+ + @else +
+ + + +

Belum ada artikel budidaya

+

Artikel akan segera tersedia

+
+ @endif + +
@endsection @push('scripts') @endpush \ No newline at end of file diff --git a/resources/views/user/artikel/detail-budidaya.blade.php b/resources/views/user/artikel/detail-budidaya.blade.php index a07ffdd..dc23921 100644 --- a/resources/views/user/artikel/detail-budidaya.blade.php +++ b/resources/views/user/artikel/detail-budidaya.blade.php @@ -1,111 +1,617 @@ @extends('layouts.user-app') -@section('page-title', '🌱 Artikel Budidaya') -@section('page-subtitle', '{{ $artikel->judul }}') +@section('page-title', 'Artikel Budidaya') +@section('page-subtitle', $artikel->judul) + +@push('styles') + +@endpush @section('content') -
+
- + {{-- ══════════════════════════════════ + KONTEN UTAMA + ══════════════════════════════════ --}}
-
- + + {{-- Header Artikel --}} +
+ + {{-- Gambar --}} @if($artikel->gambar_utama) - {{ $artikel->judul }} +
+ {{ $artikel->judul }} +
+
@else -
- 🌱 +
+ + +
@endif
- + {{-- Tags --}} @if($artikel->tags)
@foreach($artikel->tags as $tag) - {{ $tag }} + {{ $tag }} @endforeach
@endif -

{{ $artikel->judul }}

+ {{-- Judul --}} +

{{ $artikel->judul }}

-
- 📅 {{ $artikel->published_at?->format('d M Y') ?? '-' }} - @if($artikel->author) - âœī¸ {{ $artikel->author->nama }} - @endif + {{-- Meta --}} + + {{-- Deskripsi --}} @if($artikel->deskripsi_singkat) -

- {{ $artikel->deskripsi_singkat }} -

+

{{ $artikel->deskripsi_singkat }}

@endif - -
- {!! nl2br(e($artikel->konten)) !!} -
- - @if($artikel->galeri_gambar && count($artikel->galeri_gambar) > 0) -
-

- đŸ–ŧī¸ - Galeri Foto -

-
- @foreach($artikel->galeri_gambar as $foto) - Galeri + {{-- Sub-bab Accordion --}} + @if($artikel->subBab->count() > 0) +
+ +
+
+ + + + +
+

Isi Artikel

+
+ +
+ @foreach($artikel->subBab as $index => $sub) +
+ + {{-- Trigger --}} + + + {{-- Body --}} +
+ @if($sub->gambar) + {{ $sub->judul_sub }} + @endif + @if($sub->konten) +
{{ $sub->konten }}
+ @else +

Konten belum tersedia.

+ @endif +
+ +
@endforeach
+ @else +
+ + + +

Belum ada sub-bab

+
@endif +
- -
- -
-

- â„šī¸ + {{-- ══════════════════════════════════ + SIDEBAR + ══════════════════════════════════ --}} +