php - How to get the values from multiple form in one post request using laravel? -


ajax:

<script type="text/javascript">     $(document).ready(function () {         $('#finalsubmit').click(function() {               var form1 = $('#priceform').serialize();             var form2 = $('#formdescription').serialize();             var form3 = $('#additionaldescription').serialize();     //var form4 = new formdata($("#imagesform").get(0));     //alert(form4);              $.ajaxsetup({                 headers: { 'x-csrf-token':                  $('meta[name="_token"]').attr('content') }             });              $.ajax({                 url      :"{{url('/dbvalue')}}",                 type: 'post',                 data: {form1: form1, form2: form2,form3: form3},                 datatype:'json',                 success:function(data){                     alert(data);                  }              });         });     });  </script> 

this ajax code.here i'm passing values of 4 forms

controller:

public function finalsubmit(request $request) {            var_dump($_post);     $var1 = $this->addpricedetails1($request->form1);      $var2 = $this->addproductdetails1($request->form2);     $var3 = $this->addadditionalinformation1($request->form3);         //$var4 = $this->addimages($imagesform);//you dont't have      $imagesform     return response()->json(["response"=>"success"]); } 

eg. function:

public function addpricedetails1($request) {      $priceinfo = new priceinfo ;     $priceinfo->id=$this->getpricedetailsid();     $priceinfo->skuid=$request->input('skuid');     echo($priceinfo->id);       //return $request->all(); } 

also here when i'm trying echo values of $priceinfo->id echoes '0'.i don't know why

with i'm getting fatalerrorexception..call member function input() on stringshows error details

var_dump($_post) gives me array of forms values.

update:

  public function getpricedetailsid()  {   $id = mt_rand(1000000, 9999999);   $id="pd".$id;   $count=priceinfo::select('id')->where('id',$id)->count();   if($count==0)   {     return $id;   }   else   {     $this->getpricedetailsid();   }   } 

here function getpricedetailsid().

you error because input query when access object when string, can convert query string array access so.

public function addpricedetails1($request) {     parse_str($request, $input);     $priceinfo = new priceinfo ;     $priceinfo->id = $this->getpricedetailsid();     $priceinfo->skuid = $input['skuid'];     echo($priceinfo->id); } 

hope help


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -