$this->service->paginated( ...$request->validatedWithDefaults(), filters: $request->only(['is_active', 'stock', 'name']), ), 'rawMaterialNames' => $this->service->getNames(), 'filters' => $request->only(['is_active', 'stock', 'name']), 'highlight' => $request->input('highlight'), ]); } public function create(): Response { return Inertia::render('admin/master/raw-material/create'); } public function store(RawMaterialRequest $request): RedirectResponse { return $this->handleAction( fn () => $this->service->store($request->validated()), 'Bahan baku berhasil ditambahkan.', 'admin.master.raw-materials.index', 'admin.master.raw-materials.create' ); } public function edit(RawMaterial $rawMaterial): Response { return Inertia::render('admin/master/raw-material/edit', [ 'rawMaterial' => $this->service->getForEdit($rawMaterial), ]); } public function update(RawMaterialRequest $request, RawMaterial $rawMaterial): RedirectResponse { try { $this->service->update($rawMaterial, $request->validated()); } catch (ValidationException $e) { return back()->withErrors($e->errors()); } Inertia::flash('toast', ['type' => 'success', 'message' => 'Bahan baku berhasil diperbarui.']); return to_route('admin.master.raw-materials.index'); } public function destroy(RawMaterial $rawMaterial): RedirectResponse { return $this->handleAction( fn () => $this->service->destroy($rawMaterial), 'Bahan baku berhasil dihapus.', 'admin.master.raw-materials.index' ); } public function toggleStatus(RawMaterial $rawMaterial): RedirectResponse { $this->service->toggleStatus($rawMaterial); $status = $rawMaterial->fresh()->is_active ? 'Aktif' : 'Non Aktif'; Inertia::flash('toast', ['type' => 'success', 'message' => "Status bahan baku berhasil diubah menjadi {$status}."]); return back(); } public function variants(RawMaterial $rawMaterial): JsonResponse { return response()->json([ 'variants' => $this->service->getVariants($rawMaterial), ]); } }