rob897's avatar
Level 30

Help with pagination

Here is my function that checks to see which property type was chosen, then does a couple where queries. The tables (Residential, Apartment, Rental) all have identical fields just different data:

public function searchProperties(Request $request)
{
    $type = $request->input('propertyType');

    if($type == "residential")
    {
        $this->builder = Residential::where('testField', '!=',null);
    }
    elseif($type == "apartment")
    {
        $this->builder= Apartment::where('testField', '!=',null);
    }
    elseif($type == "rental")
    {
        $this->builder = Rental::where('testField', '!=',null);
    }

    if($request->input('streetName'))
    {
        $this->builder->where('streetName', 'LIKE', '%'.$request->input('streetName').'%');
    }

    $properties = $this->builder->orderBy('price)->paginate(15);

    return view('search.results',compact('properties'));
}

The result of this works fine, but and the pagination does show up correctly with the follow code in my view: {{ $properties->render() }}

Yet when I click on any of the pagination links I get this error: FatalErrorException in SearchController.php line 293: Call to undefined method Illuminate\Database\Schema\Builder::orderBy()

Any help would be appreciated.

0 likes
4 replies
J_shelfwood's avatar

I'm not sure, but if you copy-pasted the code try fixing your syntax error first. $properties = $this->builder->orderBy('price')->paginate(15);

rob897's avatar
Level 30

The query works fine meaning I get the first 15 results displayed properly. Yet any of the pagination links is what throws the exception.

rob897's avatar
Level 30

I have the builder being injected into the constructor and get the same results. What do you mean by variable type?

rob897's avatar
Level 30

At the end of this function I have the properties assigned as follows $properties = $this->builder->orderBy('field_ListPrice')->paginate(15); If I dd($properties) I do get all the properties.. The issue is when I click on the paginated links, so going to search results page 2 that error is thrown.

Please or to participate in this conversation.