thenRaw("CONCAT(SPLIT_PART(version,'-',1),'-',SPLIT_PART(version,'-',2))") ->whenRaw("version ~ '-00000000$'")->thenRaw("CONCAT(SPLIT_PART(version,'-',1),'-GIT')") ->whenRaw("version ~ '^v[0-9]+\.[0-9]+\.[0-9]+'")->thenRaw("SPLIT_PART(version,'-',1)") ->elseRaw("'unknown'"); $stats = SiteVersion::select([ DB::raw('DATE(site_versions.created_at) AS created_at'), //'site_versions.version', DB::raw('count(distinct site_id) as total') ]) ->selectRaw($case->toRaw().' AS ver') ->groupBy([DB::raw('DATE(site_versions.created_at)'),'ver']) ; return view('stats') ->with('query',$stats->get()); } }