lundi 2 mai 2016

passing data from javascript ro laravel controller and using data to add or update

I am getting error of MethodNotAllowedHttpException when I am running below code.. Code for HTML:

<h1>Temp Form</h1>
        <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>

Code for routes.php :

 Route::post('welcome/addupdate','FormController@addUpdateData');

code for controller :

 public function addUpdateData(Request $req)
 {
    $id = $req->input('id');
    if($id=="add")
    {
        $bs = new Basicusers;

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

        $bs->save();

        return "Data Successfully Added";
    }
  }

Now, what I want to is when user clicks on add button, value in variable 'data' add is passed and on controller I will check value for variable and if its add than I will perform add operation...

meanwhile if user click on edit button which provided below in form that that row will be filled in form elements and the add button is changed to update button and value of variable 'data' will be now 'update' and I want to perform update operation...

I am getting error when I am passing data using POST method moreover I don't know how to get data passed using POST method..

for GET method I am using $id = Input::get('id'); method and its working

please help me I am beginner in laravel



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

Aucun commentaire:

Enregistrer un commentaire