title: Filter by id on livewire - Laravel
body: <p>I have a table (clients_credits) that saves all the records and these records belong to a client of the table (clients), so far so good.</p>
  <p>What I want to achieve is that I filter the client id so that it shows me only the credits that correspond to a client, but I cannot find that since it shows me all the records.</p>
  <p><strong>Rutas</strong></p>
  <pre><code>Route::get('/clients/{id}/credits', [ClientCreditController::class, 'show'])-&gt;name('clients-credits-index');
  </code></pre>
  <p>My main view is managed through a controller, inside my Blade file I have a Livewire component that takes me to the table where all the records are displayed.</p>
  <p><strong>client-credit.blade.php</strong></p>
  <pre><code>&lt;x-app-layout&gt;
          @livewire('client-credit-show', ['id' =&gt; $client], key($client-&gt;id))
      &lt;/x-app-layout&gt;
  </code></pre>
  <p>The livewire component has date filtering</p>
  <p><strong>clientcreditshow.php</strong></p>
  <pre><code>public $search, $client, $userid, $report, $reportType, $dateFrom, $dateTo;
  public $sort = 'id';
  public $direction = 'desc';
  
  public function mount(){
      $this-&gt;userid = 0;
      $this-&gt;client = 0;
      $this-&gt;report = [];
      $this-&gt;reportType = 0;
  }
  
  public function render()
  {
      $this-&gt;ReportByDate();
      $users = User::all();   
      return view('livewire.client-credit-show', compact('users'));
  }
  
  
  public function ReportByDate() {
      if ($this-&gt;reportType == 0) {
          $from = Carbon::parse(Carbon::createFromDate(1999, 01, 01))-&gt;format('Y-m-d') . ' 00:00:00';
          $to = Carbon::parse(Carbon::createFromDate(2080, 12, 31))-&gt;format('Y-m-d') . ' 23:59:59';
      } else {
          $from = Carbon::parse($this-&gt;dateFrom)-&gt;format('Y-m-d') . ' 00:00:00';
          $to = Carbon::parse($this-&gt;dateTo)-&gt;format('Y-m-d') . ' 23:59:59';
      }
      if ($this-&gt;reportType == 1 &amp;&amp; ($this-&gt;dateFrom == '' || $this-&gt;dateTo == '')) {
          return;
      }
      if ($this-&gt;userid == 0) {
          $this-&gt;report = ClientCredit::join('users', 'users.id', 'clients_credits.user_id')
                                      -&gt;select('clients_credits.*', 'users.name')
                                      -&gt;where('clients_credits.created_at', 'LIKE', '%' . $this-&gt;search . '%')
                                      -&gt;whereBetween('clients_credits.created_at', [$from, $to])
                                      -&gt;orderBy($this-&gt;sort, $this-&gt;direction)
                                      -&gt;get();
      } else {
          $report = ClientCredit::join('users', 'users.id', 'clients_credits.user_id')
                                      -&gt;select('clients_credits.*', 'users.name')
                                      -&gt;whereBetween('clients_credits.date_start', [$from, $to])
                                      -&gt;where('user_id', $this-&gt;userid)
                                      -&gt;get();
      }
  }
  </code></pre>
  <p>How can I make it show me only the credits corresponding to a client?
  Thanks</p>