1

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 is my ajax code.Here I'm passing the values of four 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. for 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 to echo the values of $priceInfo->Id it echoes '0'.I don't know why

With this I'm getting FatalErrorException..call to member function input() on stringshows my error details

var_dump($_POST) gives me an 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 is my function for getpriceDetailsId().

1 Answer 1

1

You get that error because your input query when you access as object when it is string, you can convert your query string to an array to access like so.

public function addPriceDetails1($request)
{
    parse_str($request, $input);
    $priceInfo = new priceInfo ;
    $priceInfo->id = $this->getpriceDetailsId();
    $priceInfo->SKUID = $input['skuid'];
    echo($priceInfo->id);
}

Hope this help

Sign up to request clarification or add additional context in comments.

8 Comments

It works..But I'm not getting the value for $priceInfo->id
Well, for this you need show me where the getpriceDetailsId() is? Is on same controller or other?
Why you rand your ID? Is your ID is not int because I see you add string into it $id="PD".$id;?, and why you only return your $id when is 0 if($count==0)? I don't know why you write this function and its purpose ^^
yes..my ID is string..and I'm returning it when $count==0 bcz that id should not be repeated
I don't know your system so I can't help you with your function because I don't know what is use for.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.