Added Notifications
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Achievement;
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Alliance;
|
||||
use App\Models\Continent;
|
||||
use App\Models\Country;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -15,7 +18,7 @@ class AchievementController extends Controller
|
||||
$achievements = Achievement::with(['category', 'difficulty'])
|
||||
->get()
|
||||
->groupBy(fn(Achievement $a) => $a->category->name)
|
||||
->map(fn($group) => $group->sortBy('id')->values());
|
||||
->map(fn($group) => $group->sortBy('sort_order')->values());
|
||||
|
||||
$userAchievements = $user->achievements()
|
||||
->with('achievement')
|
||||
@@ -29,26 +32,72 @@ class AchievementController extends Controller
|
||||
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
|
||||
'achievements' => $achievements,
|
||||
'userAchievements' => $userAchievements,
|
||||
'loggedInUser' => auth()->user(),
|
||||
]);
|
||||
}
|
||||
|
||||
function getRegionsByCountryCode(string $countryCode)
|
||||
{
|
||||
return Country::whereCode($countryCode)
|
||||
->first()
|
||||
->regions()
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
public function specific(User $user, Achievement $achievement)
|
||||
{
|
||||
$regions = match($achievement->internal_name){
|
||||
'fun_challenges.australian_states' => Country::where('code', 'AU')->first()->regions->toArray(),
|
||||
'fun_challenges.chinese_provinces' => Country::where('code', 'CN')->first()->regions->toArray(),
|
||||
'fun_challenges.canadian_provinces' => Country::where('code', 'CA')->first()->regions->toArray(),
|
||||
'fun_challenges.us_states' => Country::where('code', 'US')->first()->regions->toArray(),
|
||||
'fun_challenges.australian_states' => $this->getRegionsByCountryCode('AU'),
|
||||
'fun_challenges.chinese_provinces' => $this->getRegionsByCountryCode('CN'),
|
||||
'fun_challenges.canadian_provinces' => $this->getRegionsByCountryCode('CA'),
|
||||
'fun_challenges.brazilian_states' => $this->getRegionsByCountryCode('BR'),
|
||||
'fun_challenges.us_states' => $this->getRegionsByCountryCode('US'),
|
||||
default => [],
|
||||
};
|
||||
|
||||
$allianceInternalName = match($achievement->internal_name){
|
||||
'airlines_alliances.all_star_alliance' => 'star_alliance',
|
||||
'airlines_alliances.all_oneworld' => 'oneworld',
|
||||
'airlines_alliances.all_skyteam' => 'skyteam',
|
||||
'airlines_alliances.all_vanilla_alliance' => 'vanilla_alliance',
|
||||
default => null,
|
||||
};
|
||||
|
||||
$continents = match($achievement->internal_name){
|
||||
'countries_continents.all_continent_pairs_one_way', 'countries_continents.all_continent_pairs_both_ways' => Continent::all()->toArray(),
|
||||
default => [],
|
||||
};
|
||||
|
||||
$alliance = null;
|
||||
$airlines = [];
|
||||
|
||||
if ($allianceInternalName) {
|
||||
$alliance = Alliance::where('internal_name', $allianceInternalName)
|
||||
->with('airlines')
|
||||
->firstOrFail();
|
||||
$airlines = $alliance->airlines()->with('country')->orderBy('name')->get();
|
||||
}
|
||||
|
||||
$aircraftFamilies = match($achievement->internal_name){
|
||||
'aircraft.all_boeing_7x7' => Aircraft::BOEING_FAMILIES,
|
||||
'aircraft.all_airbus_a3xx' => Aircraft::AIRBUS_FAMILIES,
|
||||
default => [],
|
||||
};
|
||||
|
||||
return Inertia::render('Profile/UserAchievement', [
|
||||
'user' => $user,
|
||||
'achievement' => $achievement,
|
||||
'user' => $user,
|
||||
'achievement' => $achievement,
|
||||
'loggedInUser' => auth()->user(),
|
||||
'userAchievement' => $user->achievements()->where('achievement_id', $achievement->id)->first(),
|
||||
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
|
||||
'flight_api_url' => FlightProfileController::getUserFlightApiURL($user),
|
||||
'regions' => $regions,
|
||||
'isFollowing' => auth()->check() && auth()->user()->isFollowing($user),
|
||||
'flight_api_url' => FlightProfileController::getUserFlightApiURL($user),
|
||||
'regions' => $regions,
|
||||
'alliance' => $alliance,
|
||||
'airlines' => $airlines,
|
||||
'continents' => $continents,
|
||||
'aircraft_families' => $aircraftFamilies,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user