mardi 16 octobre 2018

My pagination not going next page, returns main page

I do pagination to table. But when I click the numbers just return the main page and Url shows like this: http://example/?q=?=大阪&page=2

This how I calling the links for pagination on view.blade



And this is the controller:

$q = $request->q;
        if ($q !== null && trim($q) !== ""){//here

            $estates = \DB::table('allestates')
                ->where("building_name","LIKE", "%" . $q . "%")
                ->orWhere("address","LIKE", "%" . $q . "%")
                ->orWhere("company_name","LIKE", "%" . $q . "%")
                ->orWhere("region","LIKE", "%" . $q . "%")
                ->orderBy('price')->get();


            $showPerPage = 10;

            $perPagedData = $estates
                ->slice((request()->get('page')) * $showPerPage, $showPerPage)
                ->all();

            $estates = new \Illuminate\Pagination\LengthAwarePaginator($perPagedData, count($estates), $showPerPage, request()
                ->get('page'));


            if(count($estates) > 0){
                return view("search", compact('estates'))->withQuery($q);
            }

        }

What am I missing here? My guess is it couldn't find the next page? But why?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire