title: Get the SQL used in query when using Eloquent independent of Laravel
body: <p>I use Eloquent ORM <strong>without Laravel</strong>. For diagnostic purposes I need to know the SQL that was used to execute a query.</p>
  <p>The code is pretty simple:</p>
  <pre class="lang-php prettyprint-override"><code>// $this-&gt;hmisUsers is a new instance of the Model representing the HmisUsers table.
  $hmisModel = $this-&gt;hmisUsers;
  $hmisUsers = $hmisModel-&gt;orderBy('UserName')-&gt;get();
  
  // $hmisUsers is an Eloquent Collection object
  // How do I get what SQL was executed with `get()`?
  </code></pre>
  <p>There is a method called <code>toSql()</code> but that doesn't exist on a model object or the resulting Eloquent collection object.</p>