/** * Check for user existance and brought downline left right * Query build * * @return array[] */ public function checkUplineUser($uplineId = null) { $result = []; if (User::where('username', $uplineId)->exists()) { array_push($result, "is available"); } else { echo json_encode("User not found"); return; } $userInfo = User::where('username', $uplineId)->first(); if ($userInfo->id) { $downLineTableRow = Downline::where('user_id', $userInfo->id)->first(); $left_member_id = $downLineTableRow->left_member_id; $right_member_id = $downLineTableRow->right_member_id; if ($left_member_id == 0 && $right_member_id == 0) { array_push($result, "Left , Right"); } elseif ($left_member_id != 0 && $right_member_id == 0) { array_push($result, "Right"); } elseif ($left_member_id == 0 && $right_member_id != 0) { array_push($result, "Left"); } else { array_push($result, "No free position here. Please try another upline id"); } } else { array_push($result, "Not Valid user found"); } echo json_encode($result); }