parseDataTableQuery($request); $tableQuery['search_id'] = $request->string('search_id')->trim()->toString(); $status = $request->string('status')->toString(); $categoryId = $request->string('category_id')->toString(); $stockStatus = $request->string('stock_status')->toString(); return Inertia::render('admin/master/products/Index', [ 'products' => $this->productService->paginateForIndex($tableQuery, $status, $categoryId, $stockStatus), 'categories' => $this->categoryService->getSelectOptions(), 'filters' => $this->dataTableFilters($tableQuery, [ 'status' => $status, 'category_id' => $categoryId, 'stock_status' => $stockStatus, 'search_id' => $tableQuery['search_id'], ]), ]); } public function create(): Response { return Inertia::render('admin/master/products/Create', [ 'categories' => $this->categoryService->getSelectOptions(), ]); } public function store(ProductRequest $request): RedirectResponse { $this->productService->create($request->validated(), $request->user()); if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) { $this->flashCreated('Produk'); } else { $this->flashSuccess('Produk berhasil diajukan dan menunggu verifikasi owner.'); } return redirect()->route('admin.master.products.index'); } public function edit(Product $product): Response { return Inertia::render('admin/master/products/Edit', [ 'categories' => $this->categoryService->getSelectOptions(), 'product' => $this->productService->findForEdit($product), ]); } public function update(ProductRequest $request, Product $product): RedirectResponse { $this->productService->update($product, $request->validated(), $request->user()); if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) { $this->flashUpdated('Produk'); } else { $this->flashSuccess('Perubahan produk berhasil diajukan dan menunggu verifikasi owner.'); } return redirect()->route('admin.master.products.index'); } public function destroy(Request $request, Product $product): RedirectResponse { $this->productService->delete($product, $request->user()); if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) { $this->flashDeleted('Produk'); } else { $this->flashSuccess('Penghapusan produk berhasil diajukan dan menunggu verifikasi owner.'); } return redirect()->route('admin.master.products.index'); } public function toggleStatus(ToggleStatusRequest $request, Product $product): RedirectResponse { $this->productService->toggleStatus($product, $request->validated(), $request->user()); if ($request->user()->can(Permission::OWNER_VERIFICATIONS_VERIFY->value)) { $this->flashStatusUpdated('produk'); } else { $this->flashSuccess('Perubahan status produk berhasil diajukan dan menunggu verifikasi owner.'); } return back(); } public function show(Product $product): JsonResponse { $product->load([ 'categories', 'variants' => fn ($query) => $query ->with(['media', 'prices']) ->orderBy('created_at'), ]); $product->variants->each(function ($variant): void { $variant->setAttribute('images', MediaPresenter::collection($variant, 'images')); }); return response()->json($product); } }