diff --git a/app/Models/Domain.php b/app/Models/Domain.php index e2f572c..5bc2f1e 100644 --- a/app/Models/Domain.php +++ b/app/Models/Domain.php @@ -123,14 +123,15 @@ class Domain extends Model ->elseRaw("'all'"); return Echoarea::cacheFor(self::CACHE_TIME) - ->select(['echoareas.id','name','description','active',DB::raw('count(echoareas.id) AS count'),DB::raw('max(datetime) as last_message')]) + ->select(['echoareas.id','name','description','active',DB::raw('count(echomails.id) AS count'),DB::raw('max(datetime) as last_message')]) ->selectRaw($case->toRaw().' AS stats') - ->join('echomails',['echomails.echoarea_id'=>'echoareas.id']) + ->join('echomails',['echomails.echoarea_id'=>'echoareas.id'],NULL,NULL,'left outer') ->where('domain_id',$this->id) ->groupBy('echoareas.id') ->groupBy('echoareas.name') ->groupBy('stats') ->orderBy('echoareas.name') + ->orderBy('last_message','DESC') ->get(); }