app/Http/Controllers/CategoryController.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(); 
        $listCategories = Category::latest()->paginate(15); 
        if($request->has('search')){
            $listCategories = Category::where('name','like',"%{$request->get('search')}%")->paginate(10);
        }
        return view('admin.category.index',[
            'data' => $listCategories,
            'categories' => $categories
        ]);
    }
public function index ( Request $ request ) { $ categories = Category :: all ( ) ; $ listCategories = Category :: latest ( ) -> paginate ( 15 ) ; if ( $ request -> has ( 'search' ) ) { $ listCategories = Category :: where ( 'name' , 'like' , " % { $ request -> get ( 'search' ) } % " ) -> paginate ( 10 ) ; } return view ( 'admin.category.index' , [ 'data' => $ listCategories , 'categories' => $ categories ] ) ; }
Display a listing of the resource.
Display a listing of the resource .
// lấy toàn bộ dữ liệu // sắp sếp theo thứ tự mới nhất && phân trang