Question

I have a search form which users enter and I filter out the data then paginate. The problem is I when I paginate Laravel returns entire result

$searchFilter = arrray('id'=>true);
$building = new Building();

if (isset($searchFilter['id']))
{
    $building->where('id','=', 6);

}

return $building->paginate(20);

In the table there exist only one row with id 6. Laravel returns all the rows of the table.

However If I don't paginate it will return only the row with id 6 I want it to return paginated with applying the where operation

Was it helpful?

Solution

Figured out the answer. I should append it to $building the where operation. This is Laravel fluent works

$searchFilter = arrray('id'=>true);
$building = new Building();

if (isset($searchFilter['id']))
{
   // need to append it to building to make it work
    $building  = $building->where('id','=', 6);

}

return $building->paginate(20);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top