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

Tithira's avatar

Search and Filter Query with Jscroll

I am setting up a listing platform and so far i have made the structure. The listings are shown in a view and integrated with Jscroll. The listings view has a filter as shown below. Image of Filter

I filter the request by using when in the Model query and orderBy in the end with pagination. However the orderBy lasts for first pagination results page and not return intended results after the second page onward. From the second page onward the results are not filtered.

//Controller

	 $posts = Post::where('status','=', 3)
                        ->when($condition, function ($query, $condition) {
                            return $query->whereIn('condition', $condition);                            
                        }, function ($query) {
                            return $query->orderBy('created_at','asc');
                        })
                        ->when($make, function ($query, $make) {
                            return $query->where('make', $make);
                        }, function ($query) {
                            return $query->orderBy('created_at','asc');
                        })
			......
			->orderBy('created_at','asc')
                        ->paginate(9);

I am stuck with nowhere to continue. Any help would be greatly appreciated.

0 likes
2 replies
Tithira's avatar

Thanks a lot @michaloravec . Yesterday i tried {{ $users->appends(['sort' => 'votes'])->links() }} without really understanding the concept. Now i realized your answer receives the query string. Works like a charm. Thank you once again.

Please or to participate in this conversation.