lundi 4 juillet 2016

Accessing Users of a group

I make the following query

$group = Group::with('user.campaign')->where('groupName', 'TeamA')->get();

This returns something like the following

Collection {#429 ▼
  #items: array:1 [▼
    0 => Group {#398 ▼
      #table: "user_groups"
      #guarded: []
      #attributes: array:5 [▶]
      #original: array:5 [▶]
      #relations: array:1 [▼
        "User" => Collection {#402 ▼
          #items: array:5 [▼
            0 => User {#409 ▶}
            1 => User {#410 ▶}
            2 => User {#411 ▶}
            3 => User {#412 ▶}
            4 => User {#413 ▶}
          ]
        }
      ]
      #hidden: []
      #visible: []
      #appends: []
      #fillable: []
    }
  ]
}

So I can see User is within the relations. However, I am having issues accessing the users which are apart of the Group TeamA. If I try

$group->user

I get an error. Unfortunately, my error page at the moment only seems to say something went wrong, without any details.

How would I go about accessing the users of this group?

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire