validate([ 'mood_id' => 'required|exists:moods,id', ]); $user = auth()->user(); $mood = UserMood::updateOrCreate( [ 'user_id' => $user->id, 'date' => now()->toDateString(), ], [ 'mood_id' => $data['mood_id'], ] ); $user->increment('xp', 10); return response()->json([ 'message' => 'Mood saved successfully', 'xp' => $user->xp, 'mood' => $mood->load('mood') ]); } // Get list of all moods user has set public function getUserMoods() { $user = auth()->user(); $moods = UserMood::where('user_id', $user->id) ->with('mood') ->orderBy('date', 'desc') ->get(); return response()->json($moods); } public function getAllMoods() { $moods = Mood::all(); return response()->json($moods); } }