nickkecooper Posted June 6, 2020 Report Share Posted June 6, 2020 Hey guys! I wanted to pick your brains about possibly getting the pireps to display based on the pilots hubs. I'd like to have it so you can go to a hub and see the pireps its filled. I am unsure how to do this the clean way! I know I can perform the following @if ($pirep->user->home_airport->icao == 'KCLT') In doing it this way I lose any pagination features as it's just filtering through already gathered data. Any thoughts would be appreciated! Quote Link to comment Share on other sites More sharing options...
web541 Posted June 6, 2020 Report Share Posted June 6, 2020 (edited) So you would like a list of PIREPS for each hub, but is this filtered on the PIREP's dep/arr airport or the PIREP user's home airport? So in other words for each hub a list of PIREPS to/from that airport or a list of PIREPS from users from that hub? I'll assume the latter based on your example. Not sure where you want to display it, but I would recommend a HUBS page (if that's what you are going for): public function METHOD($icao) { $pireps = $this->pirepRepo ->with('user') ->whereHas('user', function ($query) use($icao) { return $query->where('home_airport_id', '=', $icao); }) ->paginate(); ... or if you wanted the first option public function METHOD($icao) { $where = ['dpt_airport_id' => $icao]; $orWhere = ['arr_airport_id' => $icao]; $pireps = $this->pirepRepo->scopeQuery(function($query) use ($where, $orWhere) { return $query->where($where)->orWhere($orWhere)->orderBy('created_at', 'desc'); }); $pireps->paginate(); ... I think there's a whereOrder() method somewhere but not sure if it applies to this case. Edited June 6, 2020 by web541 1 Quote Link to comment Share on other sites More sharing options...
nickkecooper Posted June 6, 2020 Author Report Share Posted June 6, 2020 Thank you! I will give this a shot, I was looking for the first option. I saw examples online on this but I was so lost on the fuction() within the query. Quote Link to comment Share on other sites More sharing options...
Administrators Nabeel Posted June 8, 2020 Administrators Report Share Posted June 8, 2020 This was something I was going to add to the airport page (eventually). @web541 has it right! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.