vendredi 22 janvier 2021

I,m trying to update data using ajax. I got my data back but when i try to save in my database it dislpays 500 error

This is My Controller

public function PoststatusChange(Request $request, $Id)
    {
        $value = $request->Id;
        //$tripid = $request->tripid;
        $tripid = $Id;
        $data = SaveReportData::where('tripid', '=', $tripid)->first();
        $datas = SaveReportData::where('Id', '=', $data->Id)->first();
        $f = SaveReportData::find($datas->Id);

        if ($data->Id == $f->Id) {
            $f->paymentstatus = $request->Id;
            $s = $f->paymentstatus;
        }

        $f->save(); //Here Lies an Error When i commented this line i got my response back 


        $string = "";
        if($f->paymentstatus == 1){
            $string = "Your Status Changed to Paid!";
        }
        if($f->paymentstatus == 2){
            $string = "Your Status Changed to Processing";
        }

        return response()->json($string);
    }

This is My Routes

Route::post('statusChange/{Id}','HomeController@PoststatusChange');

Here is My Ajax

function Report() {
        $.ajaxSetup({
          headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
          }
        });
        var status = $('#status').val();
        var tripid = $('#tripid').val();
        console.log(status);

        if(status != "" && tripid != ""){
                $.ajax({
                    url: '/statusChange/'+tripid,
                    type: "post",
                    dataType: "json",
                    cache:false,
                    data: {
                        '_token': "",
                        'Id': status,
                        'tripid': tripid,
                    },
                    success: function(response){// What to do if we succeed
                            alert(response);
                        }
                });
            
        }
        
    }

I'm Trying to get id and pass to the controller through ajax i get my response(data) back but when i tried to save the data in database using save() function it gave me 500 error



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3iJAs8s
via IFTTT

Aucun commentaire:

Enregistrer un commentaire