public function getSuggestedIterinary($ids) { // $iterinary_ids = $this->getIterinariesByPlaces($origin, $destination); //vars $points = []; $suggested; $contributions = Contribution::whereIn("iterinary_id", $ids)->get(); // dd($contributions); foreach ($contributions as $value) { array_push($points, $value->points); } $max = max($points); // dd($max); foreach ($contributions as $value) { if ($value->points == $max) { //get the specific column that has the max value of points $suggested = $value; break; } } return $suggested->iterinary_id; // dd($suggested->iterinary_id); }