title: Laravel: Uniquely identify buttons in foreach loop's table
body: <p>Hi There I have a form where a user can enter some information into forms, which is then stored in a database (posts.sql) All of the previous rows in a table in this database are displayed below this form:</p>
  
  <p>See here: <a href="http://i.imgur.com/kkExHkJ.png" rel="nofollow">http://i.imgur.com/kkExHkJ.png</a></p>
  
  <p>I am wondering how I could uniquely identify each row's "delete" and "update" button, as the buttons are not parts of the array itself; but just generate in a foreach loop.</p>
  
  <p>Like so</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>@foreach ($posts as $post)
          &lt;tr&gt;
            &lt;td&gt;{{{ $post-&gt;id }}}&lt;/td&gt;
            &lt;td&gt;{{{ $post-&gt;post_username }}}&lt;/td&gt;
            &lt;td&gt;{{{ $post-&gt;post_title }}}&lt;/td&gt;
            &lt;td&gt;{{{ $post-&gt;post_message }}}&lt;/td&gt;
            &lt;td&gt;&lt;input type="button" onclick="alert('Post Deleted')" value="Delete"&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type="submit" value="Update"&gt;&lt;/td&gt;
          &lt;/tr&gt;
  @endforeach</code></pre>
  </div>
  </div>
  </p>
  
  <p>and then perform this function to delete the post. </p>
  
  <pre class="lang-php prettyprint-override"><code>function delete_post($id)
  {
  $sql = "delete from posts where id = ?";
  DB::delete($sql, array($id));
  }
  </code></pre>
  
  <p>and display a new page with the following form where I can update a single row. using a form similar to the one below. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="true">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form method="post" action="{{{ url('update_post_action') }}}"&gt;
              &lt;input type="hidden" name="id" value="{{{ $post-&gt;id }}}"&gt;
          &lt;table&gt;
              &lt;tr&gt;
                &lt;td&gt;Post Message&lt;/td&gt; 
                &lt;td&gt;&lt;input type="text" name="post_message"value="{{{ $post-&gt;post_message }}}"&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;td colspan=2&gt;&lt;input type="submit" value="Update item"&gt;&lt;/td&gt;
            &lt;/tr&gt;
          &lt;/table&gt;
          &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>