Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

vlauciani94's avatar

Passing query data in Pagination page

Hello

I'm trying to filter homes by Price Ascending, Price Descending, Most Recent, A-Z, Z-A and I've have success with exception to the fact that the queries to not persist after the first page. Can anyone please show me a way to do it?

public function index(Request $request)
{
    $query = $request->input('queryOptions');

    if($query == 'Price Ascending'){
        $properties = Property::orderBy('price', 'asc');
    }
    if($query == 'Price Descending'){
        $properties = Property::orderBy('price', 'desc');
    }
    if($query == 'Most Recent'){
        $properties = Property::latest();
    }
    if($query == 'A-Z'){
        $properties = Property::orderBy('city', 'asc');
    }
    if($query == 'Most Recent'){
        $properties = Property::latest();
    }

    $properties = $properties->paginate(10);
    return view('property.index', compact('properties', 'query'));
}
0 likes
1 reply

Please or to participate in this conversation.