Mubeenali
6 months ago
106
20
Laravel

Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, object given always saying on create with ajax

Posted 6 months ago by Mubeenali

i am creating the question but it always says the error mentioned in title. My code id here..

In my View


 @if(Auth::check())
            <div class="product-specifications" style="margin-top:50px;background:white;height:auto;">
                   <p style='color:red;' id="questionError"></p>
                   <textarea rows="6" cols="130" style="margin-top:5px;" id="question"></textarea>
                   <br>
                  <button class="button" style="height:50px;background:#FF4500;border:none;" 
                  id="askQuestionSubmit" data-product_id="{{ $product->id }}">Ask Question</button>
                   
             </div>
  @endif

My Ajax Request:

$("#askQuestionSubmit").click(function(){
            var question = $("#question").val();
            var product_id = $(this).data(product_id);
            if(question!=""){
                $("#questionError").text("");
                  
                  //send ajax request to save question 
                   alert(question);
                  
         $.ajax({
               headers: {
                  'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                   },

           method:'POST',
          
          url:"{{route('question.add')}}",

           type:"json",

           data:{product_id:product_id,question:question},

           success:function(data){
               if(data.success){
                  toastr.success(data.success);
                  //$("ul#comments-list li").prepend(data.output);
               }
                
               
               //$("#totalCart").html(data.totalItems);



               
             
           },
      
        });///ajax ends 
  
             
                //alert(question);
            }else{

                $("#questionError").text("Please Enter Something to ask");  
            }
            
    });

In My controller :

 public function saveQuestion(Request $request)
    {
        
        $product_id = $request->product_id;
        $question   = $request->question;

        $question   = new Question;

        $question->product_id = $product_id;
        $question->question   = $question;
        $question->save();
       
        return response()->json(['success' => 'question saved ']);
  }  

The ajax request send successfully but there is problem i can not recognize.The data is not saving in database.please help me

Please sign in or create an account to participate in this conversation.