title: How to perform auto-increment inside db-select? (laravel)
body: <p>I tried this method below but its not working.<br></p>
  <pre><code>$row = 0;
  $record = DB::table('users')
    -&gt;select(
      DB::raw(&quot;{{ $row++ }} AS no&quot;),
      'users.name AS name'
    )
    -&gt;get();
  </code></pre>
  <p>I just wish these <strong>output</strong> below:</p>
  <pre><code>|no|  Name   |
  |1 | sample1 |
  |2 | sample2 |
  |3 | sample3 |
  </code></pre>
  <p>Been searching for the right syntax, but end nothing. Somebody knows how to do this. Thanks in adv.</p>
  <hr>
  <h2>[Problem Solved] Another Solution I found aside of the Marked Answer below.</h2>
  <p>Here is my code:<br></p>
  <pre><code>DB::statement(DB::raw(&quot;SET @row = '0'&quot;));
  $record = DB::table('users')
    -&gt;select(
      DB::raw(&quot;@row:=@row+1 AS no&quot;),
      'name'
    )-&gt;get();
  </code></pre>