I want to filter the display of images with this query. And it works for me but the problem is with the pagination.
I use Load More On Page Scroll. When I display images in a category and click load more, more images are displayed. But when I go to another category, like the previous category, more images are displayed without me clicking on load more.
I want more images to be displayed after entering each category, by clicking on load more.
thank you for your help.
public function render()
{
$images = Gallery::query()
->when($this->selected, function ($query, $selected) {
$query->when($selected == '1', function ($query) {
$query->where('user_id', auth()->id());
},function ($query) use ($selected) {
$query->where('category', $selected);
});
}, function ($query) {
$query->where('user_id', 1);
})->orderByDesc('created_at')->paginate($this->perPage);
return view('livewire.dashboard.add-image', compact('images'));
}