Sort achievement categories

This commit is contained in:
2026-08-21 23:22:42 +10:00
parent 3ae1e75275
commit 023ce6f964
3 changed files with 76 additions and 2 deletions
@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Models\Achievement;
use App\Models\AchievementCategory;
use App\Models\Aircraft;
use App\Models\Airport;
use App\Models\Alliance;
@@ -105,8 +106,14 @@ class UserProfileController extends Controller
$achievements = Achievement::with(['category', 'difficulty'])
->orderBy('id', 'asc')
->get()
->groupBy(fn(Achievement $a) => $a->category->name)
->map(fn($group) => $group->sortBy('sort_order')->values());
->groupBy(fn(Achievement $a) => $a->category->internal_name)
->sortBy(function ($group, $internalName) {
$index = array_search($internalName, AchievementCategory::ORDER);
return $index === false ? PHP_INT_MAX : $index;
})
->mapWithKeys(fn($group) => [
$group->first()->category->name => $group->sortBy('sort_order')->values(),
]);
$userAchievements = $user->achievements()
->with('achievement')
+10
View File
@@ -16,6 +16,16 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
*/
class AchievementCategory extends Model
{
const array ORDER = [
'number_of_flights',
'distance',
'general_flying',
'countries_and_continents',
'aircraft',
'airlines_and_alliances',
'fun_challenges',
];
protected $fillable = [
'internal_name',
'name',