title: passing data from Javascript to Laravel controller
body: <p>I'm getting the error of <code>MethodNotAllowedHttpException</code> when I run the below code:</p>
  
  <pre><code>&lt;h1&gt;Temp Form&lt;/h1&gt;
  &lt;form method="post" action="" role="form"&gt;
    &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
    &lt;div class="panel panel-default "&gt;
      &lt;div class="container"&gt;
        &lt;div class="panel-body"&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="firstName"&gt;First Name *&lt;/label&gt;
            &lt;input name="fname" type="text" class="form-control" id="firstName" placeholder="Enter First Name" required&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="lastName"&gt;Last Name *&lt;/label&gt;
            &lt;input name="lname" type="text" class="form-control" id="lastName" placeholder="Enter Last Name" required&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="qualification"&gt;Qualification *&lt;/label&gt;
            &lt;input name="qualification" type="text" class="form-control" id="qualification" placeholder="BE, MCA, MBA Etc." required&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="emailAddress"&gt;Email address *&lt;/label&gt;
            &lt;input name="email" type="email" class="form-control" id="emailAddress" placeholder="Enter Email" required&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
            &lt;label for="contactmessage"&gt;Message&lt;/label&gt;
            &lt;textarea name="desc" type="text" class="form-control" id="contactmessage" placeholder="Message" rows="2"&gt;&lt;/textarea&gt;
          &lt;/div&gt;
          &lt;input type="submit" id="add" class="btn btn-primary" onclick="addUpdateData(id)" value="Add"&gt;&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Code for routes.php :</p>
  
  <pre><code>Route::post('welcome/addupdate','FormController@addUpdateData');
  </code></pre>
  
  <p>code for controller :</p>
  
  <pre><code> public function addUpdateData(Request $req)
   {
      $id = $req-&gt;input('id');
      if($id=="add")
      {
          $bs = new Basicusers;
  
          $bs-&gt;fname = $req-&gt;fname;
          $bs-&gt;lname = $req-&gt;lname;
          $bs-&gt;qualification = $req-&gt;qualification;
          $bs-&gt;email = $req-&gt;email;
          $bs-&gt;desc = $req-&gt;desc;
  
          $bs-&gt;save();
  
          return "Data Successfully Added";
      }
    }
  </code></pre>
  
  <p>What I want is, when user clicks on add button, value in variable <code>data</code> add is passed, and on controller, I will check value for variable and if its <code>add</code>, than I will perform add operation.</p>
  
  <p>meanwhile if the user click on <code>edit</code> button which is provided below in form, that row will be filled in form elements and the add button is changed to update button and value of variable <code>data</code> will be now <code>update</code> and I want to perform update operation...</p>
  
  <p>I'm getting error when I am passing data using POST method
  moreover I don't know how to get data passed using POST method..</p>
  
  <p>for GET method I am using <code>$id = Input::get('id');</code> method and its working</p>
  
  <p>Here is JavaScript Function :</p>
  
  <pre><code>function addUpdateData(data) {
    $(function() {
      $.ajax({
        method: "post",
        url: "welcome/addupdate",
        data: {
          id: data
        },
        success: function(response) {
          alert(response);
        }
      });
    });
  }
  </code></pre>