Jump to content

Display Pireps Based on Pilots Hub


nickkecooper

Recommended Posts

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! 

Link to comment
Share on other sites

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 by web541
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...