title: Laravel: Pull data from multiple tables
body: <p>I am new to Laravel but I dont think Im writing optimised code. I am looking at getting all overdue invoices separated by clients. Invoices table and clients table. client_id is within the invoices table. I have the following below but I wanted to know if there is a better way. I would also want to grab the client name from the clients table. I have created an array so I can loop throgh accordingly on the view file, but again im not sure this is the correct way?:</p>
  
  <pre><code>$overdueClients = Invoice::where("date_paid",'0000-00-00')-&gt;where("date_due","&lt;=",date("Y-m-d"))-&gt;pluck('client_id');
  foreach($overdueClients as $overdueClient)
  {
      $invoices = Invoice::select("title","total","on_account","date","date_due")-&gt;where("date_paid",'0000-00-00')-&gt;where("date_due","&lt;=",date("Y-m-d"))-&gt;where('client_id',$overdueClient)-&gt;get();
      $return[$overdueClient][] = $invoices;
  }
  return $return;
  </code></pre>