mercredi 30 août 2017

Search Query with Pagination

When I run a search with constraints and get more than the set paginate amount, if I change the pages the search query is lost and my default page 2 is shown rather than the 2nd page of results for the query ran by a user.

How do i fix this?

        $batsQuery = Batsmen::where('approved', '=', 1)->leftJoin('reviews', 'reviews.batsmen_id', '=', 'batsmens.id')->select('batsmen.*', DB::raw('AVG(ratings) as ratings_average' ))->groupBy('batsmen.id');

        if(!empty($name)){
            $batsQuery->where('batsmenname', 'LIKE', '%'.$name.'%')->get();
        }
        if(!empty($cat)){
            $batsQuery->where('categories_id', $request->input('categories_id') )->get();
        }

        $batsmen= $batsQuery->paginate(8);

return view('page.search')->withBatsmen($batsmen)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire