is there a way to do this with Eloquent without having to run Raw queries etc?
(select count(`win`) from ((select (`win`) from entries LIMIT startOffset, limitOffset) as t1) WHERE `win`=1);
(model for 'entries' is Entry)
specifically I want to pick a range of results then do the count query. you can't just chain it as it will do the count query and then limit it as far as i can tell.
ie as far as I can see you can't do this:
Entry::offset($startOffset)->limit($limit)->whereNotNull('prize_id')->count();
say startOffset=10
and limit = 10
that would give me 10 records in all of the records between 10 and the end of the table
what I am trying to do is count the records in that range (10-20) that match the where clause.
thanks J
I solved this with
Entry::skip($startOffset)->take($limit)->get()->filter(
function($item) {
return $item->prize_id != null;
}
)->count();
what I needed to do was filter the collection returned from the limited set of results
it would be handy if whereNotNull
etc existed on Collections!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community