I have an eloquent query which returns the 10 most frequently found names in a table.
$topPeople = $model ->select(['name', DB::raw('COUNT(*) as count')]) ->groupBy('name') ->orderBy('count', 'desc') ->take(10) ->get(); This works fine for returning results but I want to update these records rather than return the data. When I use update instead of get;
$model ->select(['name', DB::raw('COUNT(*) as count')]) ->groupBy('name') ->orderBy('count', 'desc') ->take(10) ->update(['popular' => 1]); I get the error;
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'count' in 'order clause'
What is an efficient way of updating the popular field in these records?