input('search'); $query = Product::query(); if ($search) { $query->where(function ($query) use ($search) { $query->where('name', 'like', '%' . $search . '%') ->orWhere('price', 'like', '%' . $search . '%') ->orWhere('stock', 'like', '%' . $search . '%'); }); } $products = $query ->paginate(10) ->withQueryString(); return view('products.index', compact('products', 'search')); } /** * Show the form for creating a new resource. */ public function create() { return view('products.create'); } /** * Show the form for creating a new resource. */ public function store(StoreProductRequest $request) { Product::create($request->validated()); return redirect()->route('products.index'); } /** * Display the specified resource. */ public function show(Product $product) { return view('products.show', [ 'product' => $product ]); } /** * Show the form for editing the specified resource. */ public function edit(Product $product) { // return view('products.edit', [ 'product' => $product ]); } /** * Update the specified resource in storage. */ public function update(UpdateProductRequest $request, Product $product) { // $product->update($request->validated()); return redirect()->route('products.index'); } /** * Remove the specified resource from storage. */ public function destroy(Product $product) { // $product->delete(); return redirect()->route('products.index'); } }