Hello, I'm trying to make a component that lists all the assets of a user in livewire
Now I wanna make a search system for it that allows user to do some basic queries
This is like what Amazon or realstate websites have to allow users to find what they need with some options.
in my case I have two options:
- Price(Min and Max)
- Asset type(a number from 0 to 4)
What I'm trying to acheave is simple: a resualt with both these options in effect.
so I did this:
use WithPagination, WithoutUrlPagination;
private $assetType = '';
private int $_minPrice = 0;
private int $_maxPrice = 9999999999;
public $minPrice = '0';
public $maxPrice = '9999999999';
public function setType($val)
{
if (!($val >= 0 && $val <= 4)) {
$this->assetType = '';
return;
}
$this->assetType = $val;
}
public function setPrice()
{
if (is_numeric($this->minPrice)) {
$this->_minPrice = $this->minPrice;
$this->minPrice = $this->_minPrice;
} else {
$this->minPrice = 0;
$this->_minPrice = 0;
}
if (is_numeric($this->maxPrice)) {
$this->_maxPrice = $this->maxPrice;
$this->maxPrice = $this->_maxPrice;
} else {
$this->maxPrice = 9999999999;
$this->_maxPrice = 9999999999;
}
}
public function render()
{
return view('livewire.post-search', [
//if this change the next one is ignored:
'assets' => Asset::whereLike('type', '%' . $this->assetType . '%')
//if this change the previous one is ignored
->whereBetween('price_public', [$this->_minPrice, $this->_maxPrice])
->paginate(13),
]);
}
So basicly its like only one condition has effect after calling wire:change on each input like this for assetType:
<div class="items-center" wire:click='setType(1)'>
<input id="default-checkbox" type="checkbox" value="">
<label for="default-checkbox">Land</label>
</div>
or for Price:
<div>
<label for="min">
price starts from:
</label>
<input wire:model='minPrice' wire:change='setPrice' id="min" type="number">
</div>
<div class="w-full px-3 md:w-1/2">
<label for="max">
to: </label>
<input wire:model='maxPrice' wire:change='setPrice' id="max" type="number">
</div>
But when I update the value of minPrice/maxPrice or assetType the other condition will be ignored and only updated condition has effect.
Please help me find the problem if thats possible.
Thank You in Advance.