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

aarontharker's avatar

Eloquent query behaving differently in Livewire page

I'm using the following query to select posts to display

$posts = $this->category->postsPublished()
    ->whereNot(function ($query) {
        $query->withAnyTagsOfAnyType(['Guest Post', 'Press Release']);
    })
    ->when($this->year, function ($query) {
        $query->whereYear('published_at', $this->year);
    })
    ->when($this->month, function ($query) {
        $query->whereMonth('published_at', $this->month);
    })                
    ->with(['author', 'tags', 'media'])
    ->orderBy('created_at')
    ->paginate($this->perPage);

When I run the query in Tinkerwell connected to the production server, it behaves as I would expect and filters by the year (or month and year) depending on the parameters passed to it. When it is run in the render function of my Livewire page the filtering appears to be ignored. I have verified that the $this-year and $this->month values are correct on the production server and tested the Livewire page on my local development server (it seems ok there but I have a limited set of data there)

1 like
2 replies
vincent15000's avatar

If it works well on the production server, it should well on your local development server.

Are you sure that you have the same set of datas in the database ?

Snapey's avatar

make sure you have wire:key on each iteration of the results in your view

1 like

Please or to participate in this conversation.