Pagination and search conflict

I have a table and is basically built following Caleb’s tutorial: https://laracasts.com/series/guest-spotlight/episodes/3

The point is that when I’m on page 1 and I make a search all is fine.

If I’m on page 2 or higher and make a search AND the results are just one page or less worth of results the search shows “no result” as I’m actually still on page 2. If I manually go back to page 1 I see the search results.

I cannot find a way to reset to page one on every search.
I tried putting on render()

$this->page = 1;

But of course if I go on page 6 it takes me back on page 1 on every render…

Any idea?

At the bottom of your search method you could add $this->page = 1

That is what I tried but perhaps I’m doing it wrong.

This is my render method, if I add $this->page = 1 before the return it’s always set to 1 even when I click on page 2.

return view('livewire.table.card-table', [
    'rows' => $estates
     ->tableFilter('user_id', $this->filter_user)
     ->paginate($this->perPage),
]);

set to page 1 (or remove the page parameter) only when the search input changes

Right, adding this works fine:

 public function updatedSearch()
    {
        $this->page = 1;
    }
1 Like