When I try to search a product name from page 1 everything works fine, but if I try to search from another page (like page 2 or 3) I can't see the results instead I click again in page 1.
I'm able to solve that creating a new propriety ($currentPage for example), setting it to 0 by default and changing its value to 1 inside the when() method. Then I called the paginate() method like this:
Actually I had to change the code. If I set the $currentPage to one insede the when() method, after search for anything I cant change my page number because it's setted as 1. So I remove the code from the when() method. Now I'm changing its value like this:
if you have something like live searching functionality then after key change the papge should set to 1..
because search reasult may have small amount of records.
You can use debounce input to not immediately search after keychange .
example: wire:model.debounce.500ms
public $withTrashed;publicfunctionmount(){...$this->withTrashed ='';}publicfunctionrender(){...->when($this->withTrashed, function ($query){ $query->withTrashed(); }) }
When I try to search a product name from page 1 everything works fine, but if I try to search from another page (like page 2 or 3) I can't see the results instead I click again in page 1.
I'm able to solve that creating a new propriety ($currentPage for example), setting it to 0 by default and changing its value to 1 inside the when() method. Then I called the paginate() method like this:
It works but I'm wondering if there is a better approach.
My Full component at Gist
[Edit]
Actually I had to change the code. If I set the $currentPage to one insede the when() method, after search for anything I cant change my page number because it's setted as 1. So I remove the code from the when() method. Now I'm changing its value like this:
Thank you for the valuable comment, Antonio
Another better approach is set to page 1 when trying to search
I like that, although if I search for some value from another page than page 1 when I clear the search field I'm back to page one.
if you have something like live searching functionality then after key change the papge should set to 1.. because search reasult may have small amount of records.
You can use debounce input to not immediately search after keychange . example: wire:model.debounce.500ms
https://laravel-livewire.com/docs/2.x/properties#debouncing-input
if you have search button ( not for live searching ) you can use wire:model.defer
https://laravel-livewire.com/docs/2.x/properties#deferred-updating
I can't find anything about toggling soft deletes in this excelent course. However it is easy. Simply add a checkbox in the form and make it livewire:
Then, in your livewire controller, add