Answer the question
In order to leave comments, you need to log in
How to sort a grouped collection?
Laravel 5.5
There is a collection of different types of models:
модель Участник [
type = {школьник или студент}
year = год
olimp_id = связь с моделью олимпиады
rating = результат в баллах
position = место в рейтинге
]
$rating = $this->rating->groupBy(['year','olimp_id', 'model_type', 'rating']);
$rating->each(function ($year_item, $year) {
$year_item->each(function ($olimp_item) {
$olimp_item->each(function ($model_type_item) use(&$position) {
$position = 0;
$model_type_item->each(function ($rating_item) use(&$position) {
$position++;
$rating_item->each(function ($model) use($position) {
$model->update(['position' => $position]);
});
});
});
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question