Laravel Join query and Paginate data append


 

 

 Laravel Join query and Paginate data append 


  public function index(Request $request)
    {
       
        if(empty($request->all())){
            $contents=DB::table('contents')->join('divisions','contents.division_id','=','divisions.id')->join('districts','contents.district_id','=','districts.id')->join('locations','contents.location_id','=','locations.id')->select('contents.*','divisions.division','districts.district','locations.location')->orderBy('id','desc')->paginate(25);
    return view('front-page.index',compact('contents'));
}
   else{
  $contents=DB::table('contents')->join('divisions','contents.division_id','=','divisions.id')->join('districts','contents.district_id','=','districts.id')->join('locations','contents.location_id','=','locations.id')->where('categories_id','LIKE','%'.$request->cat.'%')->where('contents.district_id','LIKE','%'.$request->district.'%')->where('location','LIKE','%'.$request->location.'%')->select('contents.*','divisions.division','districts.district','locations.location')->orderBy('id','desc')->paginate(25);
            $contents->appends($request->all());
            return view('front-page.index',compact('contents'));
          
  }
    }

No comments

Powered by Blogger.