Hmm, would a conditional clause clean up your code a bit? https://laravel.com/docs/8.x/queries#conditional-clauses.
Other than that, yeah I'm just changing the query in the render function based on the (changing) state of the livewire component.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm looking for a best way to implement my local scope in the Livewire component. I have bunch of students in database and I've created a local scope age that filters by d.o.b all students - either all or over 18 yrs old.
Works fine.
I've created a livewire component that lists all of them in a table. I've created a checkbox above the table to only show adults and I was wondering what's the best way to implement the state of the checkbox in the query.
Right now I just have if statement in component logic: if selected the query has ->age() in it, if not it hasn't.
Is there a better way to do it - just changing the query the return function spits out?
Please or to participate in this conversation.