Cannot save avg using updateOrCreate Method.

Posted 5 months ago by anonymouse703

Hello everyone I cannot save avg in user table.. and there's no error in Log file.. What do I missed?

    public function changeRate(Request $request, $id){
        $rate = new Rating();
        $rate->user_id = $id;
        $rate->rating = $request->rating;
        $rate->save();

        $rateUser = DB::table('rating')
                ->where('user_id', $id)
                                ->avg('rating')
                                ->first();

        
         User::updateOrCreate(
                            ['id'=>$id],['rate'=>$rateUser]
                        );
    }

when I tried to return the $id and $userRate I have this result.

Object

id: "2"

rateUser: "3.2222"

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