title: How to delete record in laravel 5.3 using ajax request?
body: <p>I'm trying to delete record using ajax in laravel 5.3, i know this is one of the common question and there is already lots of online solutions and tutorials available about this topic. I tried some of them but most of giving me same error <code>NetworkError: 405 Method Not Allowed</code>. I tried to do this task by different angle but i'm stuck and could not found where i'm wrong, that's why i added this question for guideline.</p>
  
  <p>I'm trying following script for deleting the record.</p>
  
  <p><strong>Controller.php</strong></p>
  
  <pre><code>public function destroy($id)
  {   //For Deleting Users
      $Users = new UserModel;
      $Users = UserModel::find($id);
      $Users-&gt;delete($id);
      return response()-&gt;json([
          'success' =&gt; 'Record has been deleted successfully!'
      ]);
  }
  </code></pre>
  
  <p><strong>Routes.php</strong></p>
  
  <pre><code>Route::get('/user/delete/{id}', 'UserController@destroy');
  </code></pre>
  
  <p><strong>In View</strong></p>
  
  <pre><code>&lt;button class="deleteProduct" data-id="{{ $user-&gt;id }}" data-token="{{ csrf_token() }}" &gt;Delete Task&lt;/button&gt;
  </code></pre>
  
  <p><strong>App.js</strong></p>
  
  <pre><code>$(".deleteProduct").click(function(){
          var id = $(this).data("id");
          var token = $(this).data("token");
          $.ajax(
          {
              url: "user/delete/"+id,
              type: 'PUT',
              dataType: "JSON",
              data: {
                  "id": id,
                  "_method": 'DELETE',
                  "_token": token,
              },
              success: function ()
              {
                  console.log("it Work");
              }
          });
  
          console.log("It failed");
      });
  </code></pre>
  
  <p>When i'm click on delete button it returning me error <code>NetworkError: 405 Method Not Allowed</code> in console. Without ajax same delete function is working properly. </p>
  
  <p>Can anyone guide me where i'm wrong that i can fix the issue, i would like to appreciate if someone guide me regarding this. Thank You..</p>