diff --git a/app/Http/Controllers/Frontend/AirportController.php b/app/Http/Controllers/Frontend/AirportController.php index 784ab0ee..bc5a0cd1 100644 --- a/app/Http/Controllers/Frontend/AirportController.php +++ b/app/Http/Controllers/Frontend/AirportController.php @@ -35,22 +35,23 @@ class AirportController extends Controller public function show($id, Request $request) { $id = strtoupper($id); + $with_flights = ['airline', 'arr_airport', 'dpt_airport']; - $airport = $this->airportRepo->where('id', $id)->first(); + $airport = $this->airportRepo->with('files')->where('id', $id)->first(); if (!$airport) { Flash::error('Airport not found!'); return redirect(route('frontend.dashboard.index')); } $inbound_flights = $this->flightRepo - ->with(['dpt_airport', 'arr_airport', 'airline']) + ->with($with_flights) ->findWhere([ 'arr_airport_id' => $id, 'active' => 1, ])->all(); $outbound_flights = $this->flightRepo - ->with(['dpt_airport', 'arr_airport', 'airline']) + ->with($with_flights) ->findWhere([ 'dpt_airport_id' => $id, 'active' => 1, diff --git a/app/Http/Controllers/Frontend/DashboardController.php b/app/Http/Controllers/Frontend/DashboardController.php index 8ab9ec37..dcae679c 100644 --- a/app/Http/Controllers/Frontend/DashboardController.php +++ b/app/Http/Controllers/Frontend/DashboardController.php @@ -28,14 +28,15 @@ class DashboardController extends Controller */ public function index() { - //dd(config('backup')); $last_pirep = null; + $with_pirep = ['aircraft', 'arr_airport', 'comments', 'dpt_airport']; /** @var \App\Models\User $user */ $user = Auth::user(); + $user->loadMissing('journal'); try { - $last_pirep = $this->pirepRepo->find($user->last_pirep_id); + $last_pirep = $this->pirepRepo->with($with_pirep)->find($user->last_pirep_id); } catch (\Exception $e) { } diff --git a/app/Http/Controllers/Frontend/FlightController.php b/app/Http/Controllers/Frontend/FlightController.php index 370e7fbc..2db26ddd 100644 --- a/app/Http/Controllers/Frontend/FlightController.php +++ b/app/Http/Controllers/Frontend/FlightController.php @@ -88,6 +88,7 @@ class FlightController extends Controller /** @var \App\Models\User $user */ $user = Auth::user(); + $user->loadMissing('current_airport'); if (setting('pilots.restrict_to_company')) { $where['airline_id'] = $user->airline_id; @@ -127,9 +128,11 @@ class FlightController extends Controller $flights = $this->flightRepo->searchCriteria($request) ->with([ - 'dpt_airport', - 'arr_airport', 'airline', + 'alt_airport', + 'arr_airport', + 'dpt_airport', + 'subfleets.airline', 'simbrief' => function ($query) use ($user) { $query->where('user_id', $user->id); }, ]) @@ -215,7 +218,19 @@ class FlightController extends Controller */ public function show($id) { - $flight = $this->flightRepo->find($id); + $user_id = Auth::id(); + $with_flight = [ + 'airline', + 'alt_airport', + 'arr_airport', + 'dpt_airport', + 'subfleets.airline', + 'simbrief' => function ($query) use ($user_id) { + $query->where('user_id', $user_id); + }, + ]; + + $flight = $this->flightRepo->with($with_flight)->find($id); if (empty($flight)) { Flash::error('Flight not found!'); return redirect(route('frontend.dashboard.index')); @@ -224,7 +239,7 @@ class FlightController extends Controller $map_features = $this->geoSvc->flightGeoJson($flight); // See if the user has a bid for this flight - $bid = Bid::where(['user_id' => Auth::id(), 'flight_id' => $flight->id])->first(); + $bid = Bid::where(['user_id' => $user_id, 'flight_id' => $flight->id])->first(); return view('flights.show', [ 'flight' => $flight, diff --git a/app/Http/Controllers/Frontend/HomeController.php b/app/Http/Controllers/Frontend/HomeController.php index 4cec4b3b..b761a583 100644 --- a/app/Http/Controllers/Frontend/HomeController.php +++ b/app/Http/Controllers/Frontend/HomeController.php @@ -16,7 +16,7 @@ class HomeController extends Controller public function index() { try { - $users = User::where('state', '!=', UserState::DELETED)->orderBy('created_at', 'desc')->take(4)->get(); + $users = User::with('home_airport')->where('state', '!=', UserState::DELETED)->orderBy('created_at', 'desc')->take(4)->get(); } catch (\PDOException $e) { Log::emergency($e); return view('system/errors/database_error', [ diff --git a/app/Http/Controllers/Frontend/PirepController.php b/app/Http/Controllers/Frontend/PirepController.php index 12f8e19b..9240c70a 100644 --- a/app/Http/Controllers/Frontend/PirepController.php +++ b/app/Http/Controllers/Frontend/PirepController.php @@ -182,7 +182,7 @@ class PirepController extends Controller $where = [['user_id', $user->id]]; $where[] = ['state', '<>', PirepState::CANCELLED]; - $with = ['airline', 'aircraft', 'dpt_airport', 'arr_airport', 'fares', 'comments']; + $with = ['aircraft', 'airline', 'arr_airport', 'comments', 'dpt_airport']; $this->pirepRepo->with($with) ->pushCriteria(new WhereCriteria($request, $where)); @@ -201,7 +201,20 @@ class PirepController extends Controller */ public function show($id) { - $pirep = $this->pirepRepo->with(['simbrief'])->find($id); + $with = [ + 'acars_logs', + 'aircraft.airline', + 'airline.journal', + 'arr_airport', + 'comments', + 'dpt_airport', + 'fares.fare', + 'transactions', + 'simbrief', + 'user.rank', + ]; + + $pirep = $this->pirepRepo->with($with)->find($id); if (empty($pirep)) { Flash::error('Pirep not found'); return redirect(route('frontend.pirep.index')); diff --git a/app/Http/Controllers/Frontend/ProfileController.php b/app/Http/Controllers/Frontend/ProfileController.php index 4ba55412..a08ead38 100644 --- a/app/Http/Controllers/Frontend/ProfileController.php +++ b/app/Http/Controllers/Frontend/ProfileController.php @@ -80,9 +80,8 @@ class ProfileController extends Controller public function show($id) { /** @var \App\Models\User $user */ - $user = User::with('airline', 'awards', 'current_airport', 'fields.field', 'home_airport', 'last_pirep', 'rank') - ->where('id', $id) - ->first(); + $with = ['airline', 'awards', 'current_airport', 'fields.field', 'home_airport', 'last_pirep', 'rank']; + $user = User::with($with)->where('id', $id)->first(); if (empty($user)) { Flash::error('User not found!'); @@ -110,9 +109,7 @@ class ProfileController extends Controller public function edit(Request $request) { /** @var \App\Models\User $user */ - $user = User::with(['fields', 'fields.field']) - ->where('id', Auth::user()->id) - ->first(); + $user = User::with('fields.field')->where('id', Auth::id())->first(); if (empty($user)) { Flash::error('User not found!'); diff --git a/app/Http/Controllers/Frontend/SimBriefController.php b/app/Http/Controllers/Frontend/SimBriefController.php index 71291f44..2a6c2181 100644 --- a/app/Http/Controllers/Frontend/SimBriefController.php +++ b/app/Http/Controllers/Frontend/SimBriefController.php @@ -62,7 +62,7 @@ class SimBriefController $aircraft_id = $request->input('aircraft_id'); /** @var Flight $flight */ - $flight = $this->flightRepo->with(['fares', 'subfleets'])->find($flight_id); + $flight = $this->flightRepo->with(['airline', 'arr_airport', 'dpt_airport', 'fares.fare', 'subfleets'])->find($flight_id); if (!$flight) { flash()->error('Unknown flight'); @@ -136,7 +136,7 @@ class SimBriefController // SimBrief profile does not exists and everything else is ok // Select aircraft which will be used for calculations and details /** @var Aircraft $aircraft */ - $aircraft = Aircraft::where('id', $aircraft_id)->first(); + $aircraft = Aircraft::with(['airline'])->where('id', $aircraft_id)->first(); // Figure out the proper fares to use for this flight/aircraft $all_fares = $this->fareSvc->getFareWithOverrides($aircraft->subfleet->fares, $flight->fares); @@ -263,7 +263,7 @@ class SimBriefController $user = Auth::user(); /** @var SimBrief $simbrief */ - $simbrief = SimBrief::with(['flight'])->find($id); + $simbrief = SimBrief::with(['flight.airline', 'pirep.airline'])->find($id); if (!$simbrief) { flash()->error('SimBrief briefing not found'); return redirect(route('frontend.flights.index')); diff --git a/app/Http/Controllers/Frontend/UserController.php b/app/Http/Controllers/Frontend/UserController.php index bb8303f0..d0237a1e 100644 --- a/app/Http/Controllers/Frontend/UserController.php +++ b/app/Http/Controllers/Frontend/UserController.php @@ -30,6 +30,9 @@ class UserController extends Controller */ public function index(Request $request) { + $with = ['airline', 'current_airport', 'fields.field', 'home_airport', 'rank']; + $with_count = ['awards']; + $where = []; if (setting('pilots.hide_inactive')) { @@ -43,7 +46,8 @@ class UserController extends Controller } $users = $this->userRepo - ->with(['airline', 'current_airport']) + ->withCount($with_count) + ->with($with) ->orderBy('pilot_id', 'asc') ->paginate(); diff --git a/app/Widgets/LatestNews.php b/app/Widgets/LatestNews.php index 429b535a..5c5d523a 100644 --- a/app/Widgets/LatestNews.php +++ b/app/Widgets/LatestNews.php @@ -23,7 +23,7 @@ class LatestNews extends Widget return view('widgets.latest_news', [ 'config' => $this->config, - 'news' => $newsRepo->recent($this->config['count']), + 'news' => $newsRepo->with('user')->recent($this->config['count']), ]); } } diff --git a/app/Widgets/LatestPilots.php b/app/Widgets/LatestPilots.php index d3b479f3..f49dfa46 100644 --- a/app/Widgets/LatestPilots.php +++ b/app/Widgets/LatestPilots.php @@ -21,7 +21,7 @@ class LatestPilots extends Widget public function run() { $userRepo = app(UserRepository::class); - $userRepo = $userRepo->where('state', '!=', UserState::DELETED)->orderby('created_at', 'desc')->take($this->config['count'])->get(); + $userRepo = $userRepo->with('home_airport')->where('state', '!=', UserState::DELETED)->orderby('created_at', 'desc')->take($this->config['count'])->get(); return view('widgets.latest_pilots', [ 'config' => $this->config,