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

WINDPochima's avatar

Only one Eloquent condition works in livewire after parameter update.

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:

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.

0 likes
2 replies
WINDPochima's avatar
WINDPochima
OP
Best Answer
Level 1

Looks like I should use query() like this to stop conflicts:

    public function render()
    {
        $query = Asset::query();

        if ($this->assetType !== '') {
            $query->where('type',  $this->assetType);
        }

        if ($this->minPrice !== null && $this->maxPrice !== null) {
            $query->whereBetween('price_public', [(int)$this->minPrice, (int)$this->maxPrice]);
        }

        return view('livewire.post-search', [
            'assets' => $query->paginate(13),
        ]);
    }
1 like
Chingy's avatar

@WINDPochima You should put that $assets into a computed property. You are requerying everytime render runs.

Please or to participate in this conversation.