vendredi 29 septembre 2017

Laravel using Ajax Creating default object from empty value

Iam Trying to update my form using AJAX POST method in laravel, while submitting the form am getting error as follow (Creating default object from empty value Laravel).
Here below my code:
Here my Ajax call:

        $('.submit').click(function(){
                $.ajaxSetup({
                    headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        }
                });
            var form = $('form')[0];
            var update = new FormData(form);
            var id =$('.designNo').val();
         $.ajax({
            type:"POST",
              url:"/design_update/"+id,
                processData: false,  // Important!
                contentType: false,
                cache: false,
              data:update,
              success:function(results){
                if (results==1) {
                    $("#result").html("Upadated Successfully");
                    $('#result')[0].scrollIntoView(true);
                    $("#result").addClass("alert alert-success"); 
                      window.setTimeout(function(){
                      window.location.href = "/design";
                      }, 2000);
                  }else{
                    $('#error').html(results);
                    $('#error')[0].scrollIntoView(true);
                    $('#error').addClass("alert alert-danger");
                    }
                }
            }); 
        }); 

Here my Laravel Controller page :

public function update(Request $request, $id)
{
    // To Update
    // $validator = Validator::make($request->all(), [
    $this->validate($request,[
        'design_no'=>'required',
        'design_image'=>'image|nullable|max:1999'
    ]);
            // Handle file Upload
     if ($request->hasFile('design_image')) {
        // Get filename with image 
            $filenameWithex=$request->file('design_image');
        // Get just file name
             $filename=$_FILES['design_image']['name'];
            // $filename=pathinfo($filenameWithex,PATHINFO_FILENAME);
        // Get just ex 
            // $extension=pathinfo($filenameWithex,PATHINFO_EXTENSION);
        // File Name To Store
            $fileNameToStore=$filename;
        // Upload Image
            $path=$request->file('design_image')->storeAs('public/images',$fileNameToStore);
    }else{
        $fileNameToStore='noimage.jpg';
    }
    $design=design::find($id);
    $design->design_no=$request->input('design_no');
    $design->desg_1=$request->input('desg_1');
    $design->design_image=$fileNameToStore;
    $design->desg_2=$request->input('desg_2');
    $design->desg_3=$request->input('desg_3');
    $design->desg_4=$request->input('desg_4');
    $design->desg_5=$request->input('desg_5');
    $design->desg_6=$request->input('desg_6');    
    $design->save();
    return '1';
}  

Pls Help me to fix it ,Thanks in Advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire