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
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.
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.