I have the following query :
App\User::join('gift_sents', function($builder){ $builder->on('gift_sents.receiver_id', '=', 'users.id'); }) ->select('users.*', 'COUNT(gift_sents.receiver_id as total_posts') ->groupBy('gift_sents.id') ->orderBy('total_posts', 'ASC') ->limit(3)->get(); The count isn't working, Its supposed to be working !
The following error comes up :
Column not found: 1054 Unknown column 'COUNT(gift_sents.receiver_id' in 'field list' (SQL: selectusers.*,COUNT(gift_sents.receiver_idastotal_postsfromusersinner joingift_sentsongift_sents.receiver_id=users.idgroup bygift_sents.idorder bytotal_postsasc limit 3)
->select('users.*', 'COUNT(gift_sents.receiver_id as total_posts)')Unknown column 'count(gift_sents.receiver_id)'