Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf1a2f6cba |
@@ -3,7 +3,6 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Achievement;
|
use App\Models\Achievement;
|
||||||
use App\Models\AchievementCategory;
|
|
||||||
use App\Models\Aircraft;
|
use App\Models\Aircraft;
|
||||||
use App\Models\Airport;
|
use App\Models\Airport;
|
||||||
use App\Models\Alliance;
|
use App\Models\Alliance;
|
||||||
@@ -106,14 +105,8 @@ class UserProfileController extends Controller
|
|||||||
$achievements = Achievement::with(['category', 'difficulty'])
|
$achievements = Achievement::with(['category', 'difficulty'])
|
||||||
->orderBy('id', 'asc')
|
->orderBy('id', 'asc')
|
||||||
->get()
|
->get()
|
||||||
->groupBy(fn(Achievement $a) => $a->category->internal_name)
|
->groupBy(fn(Achievement $a) => $a->category->name)
|
||||||
->sortBy(function ($group, $internalName) {
|
->map(fn($group) => $group->sortBy('sort_order')->values());
|
||||||
$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()
|
$userAchievements = $user->achievements()
|
||||||
->with('achievement')
|
->with('achievement')
|
||||||
|
|||||||
@@ -16,16 +16,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
|||||||
*/
|
*/
|
||||||
class AchievementCategory extends Model
|
class AchievementCategory extends Model
|
||||||
{
|
{
|
||||||
const array ORDER = [
|
|
||||||
'number_of_flights',
|
|
||||||
'distance',
|
|
||||||
'general_flying',
|
|
||||||
'countries_and_continents',
|
|
||||||
'aircraft',
|
|
||||||
'airlines_and_alliances',
|
|
||||||
'fun_challenges',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'internal_name',
|
'internal_name',
|
||||||
'name',
|
'name',
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use App\Models\Achievement;
|
|
||||||
use App\Models\AchievementCategory;
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
$newCategory = AchievementCategory::create([
|
|
||||||
'internal_name' => 'number_of_flights',
|
|
||||||
'name' => 'Number of Flights',
|
|
||||||
'description' => 'Achievements for reaching flight count milestones.',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$achievementsToUpdate = [
|
|
||||||
'general_flying.first_flight',
|
|
||||||
'general_flying.10_flights',
|
|
||||||
'general_flying.500_flights',
|
|
||||||
'general_flying.50_flights',
|
|
||||||
'general_flying.100_flights',
|
|
||||||
'general_flying.1000_flights',
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($achievementsToUpdate as $internalName) {
|
|
||||||
$achievement = Achievement::where('internal_name', $internalName)->first();
|
|
||||||
|
|
||||||
if (!$achievement) {
|
|
||||||
continue; // or throw, depending how strict you want this
|
|
||||||
}
|
|
||||||
|
|
||||||
$achievement->update([
|
|
||||||
'achievement_category_id' => $newCategory->id,
|
|
||||||
'internal_name' => str_replace('general_flying.', 'number_of_flights.', $internalName),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
$oldCategory = AchievementCategory::where('internal_name', 'general_flying')->first();
|
|
||||||
|
|
||||||
if ($oldCategory) {
|
|
||||||
Achievement::where('internal_name', 'like', 'number_of_flights.%')
|
|
||||||
->get()
|
|
||||||
->each(function (Achievement $achievement) use ($oldCategory) {
|
|
||||||
$achievement->update([
|
|
||||||
'achievement_category_id' => $oldCategory->id,
|
|
||||||
'internal_name' => str_replace('number_of_flights.', 'general_flying.', $achievement->internal_name),
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
AchievementCategory::where('internal_name', 'number_of_flights')->delete();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user