Skip to content
Discussion options

You must be logged in to vote

I revisited this some time later, and then I realized my smooth brain missed this very Eloquent expression that actually works:

// no psalm warnings! very nice.
$distinctCount = Model::query()->distinct('id')->count();

Then, it actually boils down to "inadequate understanding of Laravel". And understandably, Taylor is uninterested to implement this.

Update: for more complicated queries e.g. SELECT COUNT(*) FROM (SELECT GROUP BY HAVING), I can just do

$distinctCount = Model::query()->fromSub( /* ... */ )->count();

It really is about the lack of understanding.


@shaedrich maybe something similar can be said for your k, COUNT(*) ... GROUP BY k case...? Maybe the correct (& clean) expression …

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@shaedrich
Comment options

@Vectorial1024
Comment options

@shaedrich
Comment options

@Vectorial1024
Comment options

Answer selected by Vectorial1024
@ghost
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants