query('search', '')); return view('stock-details.index', [ 'items' => UniformItem::with('variants') ->when($term, fn ($query) => $query->where(fn ($query) => $query ->where('name', 'like', "%{$term}%") ->orWhere('code', 'like', "%{$term}%") ->orWhere('material', 'like', "%{$term}%") ->orWhere('color', 'like', "%{$term}%"))) ->orderBy('name')->paginate(10)->withQueryString(), ]); } public function update(Request $request, UniformItem $uniformItem) { $data = $request->validate([ 'material' => ['nullable', 'string', 'max:150'], 'color' => ['nullable', 'string', 'max:100'], 'care_instructions' => ['nullable', 'string', 'max:1000'], 'description' => ['nullable', 'string', 'max:1000'], 'front_image' => ['nullable', 'image', 'max:4096'], 'back_image' => ['nullable', 'image', 'max:4096'], ]); foreach (['front_image', 'back_image'] as $field) { if ($request->hasFile($field)) { if ($uniformItem->{$field}) { Storage::disk('public')->delete($uniformItem->{$field}); } $data[$field] = $request->file($field)->store('uniforms', 'public'); } } $uniformItem->update($data); return back()->with('success', "Details updated for {$uniformItem->name}."); } }