title: Communication between filter component and table component in livewire
body: <p>I have a component that I want to split into two parts, a filtering part and a table part. Now I know I need to somehow use the livewire events, but I am not sure how to create my functions in order to make the query work.</p>
  <pre><code>public function render()
      {
  
          $stations = Station::query()
                      -&gt;search($this-&gt;search)
                      -&gt;orderBy($this-&gt;sortBy, $this-&gt;sortDirection)
                      -&gt;Paginate($this-&gt;perPage);
  
  
          return view('livewire.workbooks-table', [
              
              'stations' =&gt; $stations,
              'stations'=&gt;Station::when($this-&gt;byCpm, function($query){
                                  $query-&gt;Where('CPM', $this-&gt;byCpm);
                                  })
                                  -&gt;when($this-&gt;byStartDay, function($query){
                                      $query-&gt;Where('StartDay', $this-&gt;byStartDay);
                                      })
                                  -&gt;when($this-&gt;byEndDay, function($query){
                                      $query-&gt;Where('EndDay', $this-&gt;byEndDay);
                                      })
                                  -&gt;when($this-&gt;byStartTime, function($query){
                                      $query-&gt;Where('StartTime', $this-&gt;byStartTime);
                                      })
                                  -&gt;when($this-&gt;byEndTime, function($query){
                                      $query-&gt;Where('EndTime', $this-&gt;byEndTime);
                                      })
                                  -&gt;when($this-&gt;byOwner, function($query){
                                      $query-&gt;Where('owner_id', $this-&gt;byOwner);
                                      })
                                  -&gt;when($this-&gt;byFormat, function($query){
                                      $query-&gt;Where('format_id', $this-&gt;byFormat);
                                      })
                                  -&gt;when($this-&gt;byMarketCity, function($query){
                                      $query-&gt;Where('market_city_id', $this-&gt;byMarketCity);
                                      })
                                  -&gt;when($this-&gt;byMarketState, function($query){
                                      $query-&gt;Where('market_state_id', $this-&gt;byMarketState);
                                      })
                                  -&gt;when($this-&gt;minCPM, function($query){
                                      $query-&gt;where('CPM', '&gt;=', $this-&gt;minCPM.'%');
                                      })
                                  -&gt;when($this-&gt;maxCPM, function($query){
                                      $query-&gt;where('CPM', '&lt;=', $this-&gt;maxCPM.'%');
                                      })
                                      -&gt;search($this-&gt;search)
                                      -&gt;orderBy($this-&gt;sortBy, $this-&gt;sortDirection)
                                      -&gt;Paginate($this-&gt;perPage),
              
    
          ]);
      }
  </code></pre>
  <p>This is how one of the filter works</p>
  <pre><code>&lt;div class=&quot;w-1/6 relative mx-1&quot;&gt;Format
       &lt;select wire:model=&quot;byFormat&quot; class=&quot;block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500&quot; id=&quot;grid-state&quot; placeholder=&quot;Format&quot;&gt;
            &lt;option value=&quot;&quot; &gt;Select Format&lt;/option&gt;
            @foreach($formats as $format)
               &lt;option value=&quot;{{ $format-&gt;id }}&quot; &gt;{{ $format-&gt;format }}&lt;/option&gt;
            @endforeach
      &lt;/select&gt;
  &lt;/div&gt;
  </code></pre>
  <p>And the table is just a regular table. My question would be. Is there a nicer way to do the query such that it's not all in render and I can actually use the events or is there any way I could use the events with what I have right now</p>