app/Http/Controllers/Dashboard/ProductController.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)
    {
        $categories = Category::all();
        $products = Product::when($request->search, function ($q) use ($request) {
            return $q->whereTranslationLike('name', '%' . $request->search . '%');
        })->when($request->category_id, function ($q) use ($request) {
            return $q->where('category_id', $request->category_id);
        })->latest()->paginate(5);
        return view('dashboard.products.index',compact('products','categories'));
    }
public function index ( Request $ request ) { $ categories = Category :: all ( ) ; $ products = Product :: when ( $ request -> search , function ( $ q ) use ( $ request ) { return $ q -> whereTranslationLike ( 'name' , '%' . $ request -> search . '%' ) ; } ) -> when ( $ request -> category_id , function ( $ q ) use ( $ request ) { return $ q -> where ( 'category_id' , $ request -> category_id ) ; } ) -> latest ( ) -> paginate ( 5 ) ; return view ( 'dashboard.products.index' , compact ( 'products' , 'categories' ) ) ; }
Display a listing of the resource.
Display a listing of the resource .