简体   繁体   中英

Laravel Eloquent Update/Insert not working

I have ajax call from view to route

this is my view:

$.ajax({
                    url: "{{URL::to('Update_toggle')}}",
                    type: "POST",
                    data: {
                        'id' : id ,
                        'status' : val,
                        'case_id': caseID
                    },
                    dataType: 'json',
                    success: function(result){
                            alert("Details Saved" +result.t);
                    }
                });

this is my controller which works fine:

 public function Update_toggle(Request $request)
    {
        $case_id=$request->case_id;
        $id=$request->id;
        $status=$request->status;
        $toggle=tblClientRequest::where('case_id', 1)
            ->update([$request->id => $request->status]);
        dd($toggle);
}

this is my controller which does not work:

public function Update_toggle(Request $request)
    {
        $case_id=$request->case_id;
        $id=$request->id;
        $status=$request->status;
        $toggle=tblClientRequest::where('case_id', $case_id)
            ->update([$request->id => $request->status]);
        dd($toggle);
}

this is what it returns in console.log:

0

when I give the number in where function it works fine but when i give the post variable to it does not update the table.

Thanks in advance

ok i have got it

Request $request variable is returning string so typecast it to integer

$case_id = (int)$request->case_id;

then it worked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM