It sounds like the issue you're experiencing may be related to Livewire's reactivity and lifecycle hooks. When you update a property that is bound to wire:model, Livewire will re-render the component and call the render method again. If your loadShows method is not called again after the update, the $shows property may not be properly populated.
Here's a potential solution to ensure that your loadShows method is called whenever the filterPrivate property changes:
// Controller
use Livewire\Component;
class ShowEventsComponent extends Component
{
public $filterPrivate = false;
public $shows = [];
public function mount()
{
$this->loadShows();
}
public function updatedFilterPrivate()
{
$this->loadShows();
}
public function loadShows()
{
$currentTimestamp = now()->timestamp;
$query = Event::with('socialLinks', 'details')
->where('Date', '>=', $currentTimestamp)
->where('Status', 'Booked');
if ($this->filterPrivate) {
// Apply additional filtering for private shows if needed
}
$this->shows = $query->get();
}
public function render()
{
return view('livewire.show-events');
}
}
{{-- View --}}
<div>
<input type="checkbox" wire:model="filterPrivate"> Show private events
</div>
@foreach($shows as $show)
{{-- show info --}}
@endforeach
In this solution, I've added an updatedFilterPrivate method to the Livewire component. This method is a lifecycle hook that gets called automatically by Livewire whenever the filterPrivate property changes. Inside this method, we call loadShows to refresh the list of shows based on the new filter value.
Additionally, I've added a mount method, which is another lifecycle hook that is called when the component is initially mounted. This ensures that loadShows is called when the component is first loaded, populating the $shows property.
Make sure that your Livewire component is properly set up to use these lifecycle hooks and that the render method returns the correct view. With these changes, your filtering checkbox should work as expected, and the shows should be displayed correctly when the checkbox is toggled.