Answer the question
In order to leave comments, you need to log in
How to get the sequence number of a row in a selection with Eloquent ORM?
For example, I have a database of cities with a population.
I need Chelyabinsk and its place in terms of population among cities.
I get cities, sort them by population, but how to get its ordinal number in the selection?
$chelyabinsk_id = 100;
$city = City::where('people', '>', 100000)->orderBy('people')->?
Answer the question
In order to leave comments, you need to log in
Get the city number by its id:
$chelyabinsk_id = 100;
$сities = City::where('people', '>', 100000)->orderBy('people')->get();
$position = $сities->where('id', $chelyabinsk_id)->keys()->first());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question