diff --git a/app/Http/Controllers/admin/BuketController.php b/app/Http/Controllers/admin/BuketController.php index 8279a50..0c82347 100644 --- a/app/Http/Controllers/admin/BuketController.php +++ b/app/Http/Controllers/admin/BuketController.php @@ -3,63 +3,150 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Models\Buket; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Validator; +use Illuminate\Support\Facades\File; class BuketController extends Controller { - /** - * Display a listing of the resource. - */ public function index() { - return view('admin.produk-buket'); + $buket = Buket::latest()->get(); + + return view('admin.produk-buket.index', compact('buket')); } - /** - * Show the form for creating a new resource. - */ - public function create() - { - // - } - - /** - * Store a newly created resource in storage. - */ public function store(Request $request) { - // + $validator = Validator::make($request->all(), [ + 'nama' => 'required|string|min:3|max:100', + 'ukuran' => 'required|in:S,M,L', + 'kategori' => 'required|in:single,fresh,premium_fresh,artificial', + 'harga' => 'required|numeric|min:0', + 'request_khusus' => 'nullable|string|max:255', + 'deskripsi' => 'required|string|min:10', + 'foto' => 'required|image|mimes:jpeg,png,jpg|max:2048', + ], [ + // Detail Pesan Kustom menggunakan :attribute + 'required' => 'Kolom :attribute tidak boleh kosong.', + 'string' => 'Input :attribute harus berupa teks valid.', + 'min' => ':attribute terlalu pendek, minimal harus :min karakter.', + 'max' => ':attribute melebihi batas, maksimal :max karakter/KB.', + 'in' => 'Pilihan :attribute tidak sesuai dengan data yang tersedia.', + 'numeric' => ':attribute harus berupa angka.', + 'image' => ':attribute harus berupa file gambar (foto).', + 'mimes' => 'Format :attribute tidak didukung. Gunakan format: jpeg, png, atau jpg.', + 'max.file' => 'Ukuran :attribute terlalu besar, maksimal adalah 2MB.', + ], [ + // Alias Atribut agar pesan lebih ramah pengguna + 'nama' => 'nama buket', + 'ukuran' => 'ukuran buket', + 'kategori' => 'kategori buket', + 'harga' => 'harga', + 'request_khusus' => 'request khusus', + 'deskripsi' => 'deskripsi produk', + 'foto' => 'foto produk', + ]); + if ($validator->fails()) { + return redirect()->back() + ->withErrors($validator) + ->withInput() + ->with('error_modal', 'create'); + } + + $path = null; + if ($request->hasFile('foto')) { + $file = $request->file('foto'); + $filename = time() . '_' . $file->getClientOriginalName(); + + $file->move(public_path('img/buket'), $filename); + + $path = 'img/buket/' . $filename; + } + + Buket::create([ + 'nama' => $request->nama, + 'ukuran' => $request->ukuran, + 'kategori' => $request->kategori, + 'harga' => $request->harga, + 'request_khusus' => $request->request_khusus, + 'deskripsi' => $request->deskripsi, + 'foto' => $path, + ]); + + return redirect()->back()->with('success', 'Produk buket berhasil ditambahkan!'); } - /** - * Display the specified resource. - */ - public function show(string $id) - { - // - } - - /** - * Show the form for editing the specified resource. - */ - public function edit(string $id) - { - // - } - - /** - * Update the specified resource in storage. - */ public function update(Request $request, string $id) { - // + $buket = Buket::findOrFail($id); + + $validator = Validator::make($request->all(), [ + 'nama' => 'required|string|min:3|max:100', + 'ukuran' => 'required|in:S,M,L', + 'kategori' => 'required|in:single,fresh,premium_fresh,artificial', + 'harga' => 'required|numeric|min:0', + 'request_khusus' => 'nullable|string|max:255', + 'deskripsi' => 'required|string|min:10', + 'foto' => 'nullable|image|mimes:jpeg,png,jpg|max:2048', + ], [ + // Detail Pesan Kustom menggunakan :attribute + 'required' => 'Kolom :attribute tidak boleh kosong.', + 'string' => 'Input :attribute harus berupa teks valid.', + 'min' => ':attribute terlalu pendek, minimal harus :min karakter.', + 'max' => ':attribute melebihi batas, maksimal :max karakter/KB.', + 'in' => 'Pilihan :attribute tidak sesuai dengan data yang tersedia.', + 'numeric' => ':attribute harus berupa angka.', + 'image' => ':attribute harus berupa file gambar (foto).', + 'mimes' => 'Format :attribute tidak didukung. Gunakan format: jpeg, png, atau jpg.', + 'max.file' => 'Ukuran :attribute terlalu besar, maksimal adalah 2MB.', + ], [ + // Alias Atribut agar pesan lebih ramah pengguna + 'nama' => 'nama buket', + 'ukuran' => 'ukuran buket', + 'kategori' => 'kategori buket', + 'harga' => 'harga', + 'request_khusus' => 'request khusus', + 'deskripsi' => 'deskripsi produk', + 'foto' => 'foto produk', + ]); + if ($validator->fails()) { + return redirect()->back() + ->withErrors($validator) + ->withInput() + ->with('error_id', $id); + } + + $data = $request->only(['nama', 'ukuran', 'kategori', 'harga', 'request_khusus', 'deskripsi']); + + if ($request->hasFile('foto')) { + // 1. Hapus foto lama jika ada + if ($buket->foto && file_exists(public_path($buket->foto))) { + File::delete(public_path($buket->foto)); + } + + // 2. Upload foto baru + $file = $request->file('foto'); + $filename = time() . '_' . $file->getClientOriginalName(); + $file->move(public_path('img/buket'), $filename); + $data['foto'] = 'img/buket/' . $filename; + } + + $buket->update($data); + + return redirect()->back()->with('success', 'Produk buket berhasil diperbarui!'); } - /** - * Remove the specified resource from storage. - */ public function destroy(string $id) { - // + $buket = Buket::findOrFail($id); + + if ($buket->foto && File::exists(public_path($buket->foto))) { + File::delete(public_path($buket->foto)); + } + $buket->delete(); + + return redirect()->back()->with('success', 'Produk dan foto berhasil dihapus permanen!'); } } diff --git a/app/Models/Buket.php b/app/Models/Buket.php index 59b994e..c4b85fc 100644 --- a/app/Models/Buket.php +++ b/app/Models/Buket.php @@ -15,6 +15,8 @@ class Buket extends Model protected $fillable = [ 'nama', 'deskripsi', + 'request_khusus', + 'ucapan', 'harga', 'foto', 'kategori', // Enum diff --git a/database/migrations/2025_12_26_150422_create_bukets_table.php b/database/migrations/2025_12_26_150422_create_bukets_table.php index 83274e3..3dd1f8c 100644 --- a/database/migrations/2025_12_26_150422_create_bukets_table.php +++ b/database/migrations/2025_12_26_150422_create_bukets_table.php @@ -15,6 +15,7 @@ public function up(): void $table->id('id_buket'); $table->string('nama'); $table->text('deskripsi')->nullable(); + $table->text('request_khusus')->nullable(); $table->decimal('harga', 10, 2); // Format uang $table->string('foto')->nullable(); // Enum sesuai diskusi Wireframe & ERD diff --git a/public/img/buket/1766817409_artificial flowers-1.jpg b/public/img/buket/1766817409_artificial flowers-1.jpg new file mode 100644 index 0000000..eed0cda Binary files /dev/null and b/public/img/buket/1766817409_artificial flowers-1.jpg differ diff --git a/public/img/buket/artificial-tulip.jpg b/public/img/buket/artificial-tulip.jpg new file mode 100644 index 0000000..2101a81 Binary files /dev/null and b/public/img/buket/artificial-tulip.jpg differ diff --git a/public/img/buket/babybreath.jpg b/public/img/buket/babybreath.jpg new file mode 100644 index 0000000..ae7557c Binary files /dev/null and b/public/img/buket/babybreath.jpg differ diff --git a/public/img/buket/buket2.jpg b/public/img/buket/buket2.jpg new file mode 100644 index 0000000..5afdb71 Binary files /dev/null and b/public/img/buket/buket2.jpg differ diff --git a/public/img/buket/buket3.jpg b/public/img/buket/buket3.jpg new file mode 100644 index 0000000..970cb6f Binary files /dev/null and b/public/img/buket/buket3.jpg differ diff --git a/public/img/buket/garbera.jpg b/public/img/buket/garbera.jpg new file mode 100644 index 0000000..3e50d4a Binary files /dev/null and b/public/img/buket/garbera.jpg differ diff --git a/public/img/buket/gran-buket.jpg b/public/img/buket/gran-buket.jpg new file mode 100644 index 0000000..ff2e368 Binary files /dev/null and b/public/img/buket/gran-buket.jpg differ diff --git a/public/img/buket/hidraangea.jpg b/public/img/buket/hidraangea.jpg new file mode 100644 index 0000000..fc3454e Binary files /dev/null and b/public/img/buket/hidraangea.jpg differ diff --git a/public/img/buket/lavender.jpg b/public/img/buket/lavender.jpg new file mode 100644 index 0000000..30aa4c6 Binary files /dev/null and b/public/img/buket/lavender.jpg differ diff --git a/public/img/buket/mawar-merah-premium.jpg b/public/img/buket/mawar-merah-premium.jpg new file mode 100644 index 0000000..95a7171 Binary files /dev/null and b/public/img/buket/mawar-merah-premium.jpg differ diff --git a/public/img/buket/pastel-peony.jpg b/public/img/buket/pastel-peony.jpg new file mode 100644 index 0000000..4eaec95 Binary files /dev/null and b/public/img/buket/pastel-peony.jpg differ diff --git a/public/img/buket/single-sunflower.jpg b/public/img/buket/single-sunflower.jpg new file mode 100644 index 0000000..f620c33 Binary files /dev/null and b/public/img/buket/single-sunflower.jpg differ diff --git a/public/img/buket/sunflower.jpg b/public/img/buket/sunflower.jpg new file mode 100644 index 0000000..6fcb25a Binary files /dev/null and b/public/img/buket/sunflower.jpg differ diff --git a/public/img/buket/white-lily.jpg b/public/img/buket/white-lily.jpg new file mode 100644 index 0000000..0cbe6e2 Binary files /dev/null and b/public/img/buket/white-lily.jpg differ diff --git a/resources/views/admin/produk-buket/index.blade.php b/resources/views/admin/produk-buket/index.blade.php index dc8a07e..75ebd34 100644 --- a/resources/views/admin/produk-buket/index.blade.php +++ b/resources/views/admin/produk-buket/index.blade.php @@ -3,6 +3,21 @@ @section('title', 'Produk Buket') @section('content') + {{-- ALERT SUKSES --}} + @if (session('success')) + + @endif + + {{-- ALERT ERROR UMUM (Jika ada error selain validasi modal) --}} + @if (session('error')) + + @endif
@@ -15,36 +30,50 @@ - - - - - - + + + + + + - - - - - - - - + @forelse ($buket as $b) + + + + + + + + + @include('admin.produk-buket.partials.modal-show') + @include('admin.produk-buket.partials.modal-edit') + @include('admin.produk-buket.partials.modal-delete') + @empty + + + + @endforelse
No.Nama BuketDeskripsiHargaFotoAksiNo.Nama BuketDeskripsiHargaFotoAksi
Graidenvehicula.aliquet@semconsequat.co.uk076 4820 8838OffenburgOffenburg - - - - - - - - - -
{{ $loop->iteration }}{{ $b->nama }}{{ Str::limit($b->deskripsi, 50) }}Rp {{ number_format($b->harga, 0, ',', '.') }} + Foto Produk + + + + + + + + + + + + +
Tidak ada data buket.
@@ -52,7 +81,86 @@
@include('admin.produk-buket.partials.modal-create') - @include('admin.produk-buket.partials.modal-show') - @include('admin.produk-buket.partials.modal-edit') - @include('admin.produk-buket.partials.modal-delete') + @push('scripts') + + @endpush @endsection diff --git a/resources/views/admin/produk-buket/partials/modal-create.blade.php b/resources/views/admin/produk-buket/partials/modal-create.blade.php index 25d607f..571c9c6 100644 --- a/resources/views/admin/produk-buket/partials/modal-create.blade.php +++ b/resources/views/admin/produk-buket/partials/modal-create.blade.php @@ -1,76 +1,142 @@