mardi 3 mai 2016

MethodNotAllowedHttpException in RouteCollection.php line 219:

I am getting MethodNotAllowedHttpException when I run the code

here is my code for HTML

<form method="POST" action="" role="form">



       <input type="hidden" name="_token" value="">

      <div class="panel panel-default ">

        <div class="container">

        <div class="panel-body">
          <div class="form-group">
            <label for="firstName">First Name *</label>
            <input name="fname" type="text" class="form-control" id="firstName" placeholder="Enter First Name" required>
          </div>

          <div class="form-group">
            <label for="lastName">Last Name *</label>
            <input name="lname" type="text" class="form-control" id="lastName" placeholder="Enter Last Name" required>
          </div>

          <div class="form-group">
            <label for="qualification">Qualification *</label>
            <input name="qualification" type="text" class="form-control" id="qualification" placeholder="BE, MCA, MBA Etc." required>
          </div>

          <div class="form-group">
            <label for="emailAddress">Email address *</label>
            <input name="email" type="email" class="form-control" id="emailAddress" placeholder="Enter Email" required>
          </div>

          <div class="form-group">
            <label for="contactmessage">Message</label>            
            <textarea name="desc" type="text" class="form-control" id="contactmessage" placeholder="Message" rows="2"></textarea>
          </div>              





            <input type="submit" id="add" class="btn btn-primary" onclick="addUpdateData(id)" value="Add"></button>
          </div>
      </div>
    </div></form> 

Here is javascript function

function addUpdateData(data)
{

if(data=="add")
{

  $(function(){
  $.ajax({
    method : "POST",
    url: "welcome/add",                
    data: {id: data},
    success : function(response)
    {
      alert(response);
      window.location.reload();

    });
  });

}
else
{
$(function(){
  $.ajax({
    method : "post",
    url: "welcome/update",        
    data: {id: data},        
    success : function(response)
    {
      alert(response);
      window.location.reload();
    }

  });


});
 } 
}

Here is code of routes.php

Route::post('welcome/add','FormController@addData');
Route::post('welcome/update','FormController@updateData');

here is code for Controller addData function

public function addData()
{
    $bs = new Basicusers; //model from database
    $bs->fname = $req->fname;
    $bs->lname = $req->lname;
    $bs->qualification = $req->qualification;
    $bs->email = $req->email;
    $bs->desc = $req->desc;
    $bs->save();
    return back();
}

updateData Function

public function updateData($id, Request $req)
{
    $bs = new Basicusers; //model from database

    $bs->fname = $req->fname;
    $bs->lname = $req->lname;
    $bs->qualification = $req->qualification;
    $bs->email = $req->email;
    $bs->desc = $req->desc;

    $olddata = Basicusers::find($id); //finding data by ID

    $olddata.update($bs); //overwrite new data to specific ID
    return back();
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1rlOD7l
via IFTTT

Aucun commentaire:

Enregistrer un commentaire