title: Laravel Delete button not working with Ajax call
body: <p>I have a Laravel post application where I create and display posts. I am now trying to delete a post using an Ajax call. Let's say I have 10 posts displaying. When I click on the delete button of the first post, I get a <code>405 Method Not Allowed</code> error. When I click on the delete button on any of the posts below, absolutely nothing happens, no error or warning message. Please take note that my CSRF tokens are set up and working. Any help or suggestions will be appreciated.</p>
  
  <p>Here is the HTML:</p>
  
  <pre><code>    @foreach($posts as $post)
      &lt;div class="postContainer" id="post{{ $post-&gt;id }}"&gt;
        &lt;h4 class="postHeading" id="showtitle"&gt;{{ $post-&gt;title }}&lt;/h4&gt;
        &lt;p class="post" id="postBody"&gt;{{ $post-&gt;post }}&lt;/p&gt;
        &lt;span class="authorName" id="showauthor"&gt;{{ $post-&gt;author }}&lt;/span&gt;
        &lt;span class="postDate" id="showpostDate"&gt;{{ $post-&gt;created_at }}&lt;/span&gt;
        &lt;input type="submit" name="delete" id="delete" value="Delete" data-id="{{ $post-&gt;id }}"&gt;
      &lt;/div&gt;
      @endforeach
      &lt;div class="message" id="message"&gt;
  
      &lt;/div&gt;
  </code></pre>
  
  <p>Here is my Ajax call:</p>
  
  <pre><code>    $("#delete").on("click", function(){
  
        var id = $(this).attr('data-id');
  
        $.ajaxSetup({
          headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr("content")
          }
        });
  
        $.ajax({
          url: '/index/delete/' + id,
          type: "POST",
          data: {_method: 'delete'},
          success:function(response){
            $("#message").append("&lt;div&gt;" + response.message + "&lt;/div&gt;");
          },
        });
  
      });
  </code></pre>
  
  <p>Here is my Route:</p>
  
  <pre><code>   Route::post('/index/delete/{id}', 'HomeController@delete');
  </code></pre>
  
  <p>Here is my controller:</p>
  
  <pre><code>public function delete($id){
    Post::find($id)-&gt;delete();
    return redirect('/');
  }
  </code></pre>