app/Http/Controllers/ProductController2.php
/**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
Display a listing of the resource.
@return \Illuminate\Http\Response
Display a listing of the resource . @return \ Illuminate \ Http \ Response
public function index(Request $request)
    {
        if ($request->category !== null) {
            $products = Product::where('category1', $request->category)->orwhere('category2', $request->category)->orwhere('category3', $request->category)->orwhere('category4', $request->category)->orwhere('category5', $request->category)->paginate(15);
        }else{
            $products = Product::all();
        };
            $categories = Category::all(); 
            $selected_category = Category::find($request->category);
            return view('products.index', ['products' => $products,'categories' => $categories, 'selected_category'=>$selected_category]);
    }
public function index ( Request $ request ) { if ( $ request -> category !== null ) { $ products = Product :: where ( 'category1' , $ request -> category ) -> orwhere ( 'category2' , $ request -> category ) -> orwhere ( 'category3' , $ request -> category ) -> orwhere ( 'category4' , $ request -> category ) -> orwhere ( 'category5' , $ request -> category ) -> paginate ( 15 ) ; } else { $ products = Product :: all ( ) ; } ; $ categories = Category :: all ( ) ; $ selected_category = Category :: find ( $ request -> category ) ; return view ( 'products.index' , [ 'products' => $ products , 'categories' => $ categories , 'selected_category' => $ selected_category ] ) ; }
Display a listing of the resource.
Display a listing of the resource .