mpociot/teamwork

Get specific data (e.g. email) from all users of my teams

jadamec opened this issue · 1 comments

Hi guys, I'd like to create an array of emails from all the users of my teams. Basically, I'm looking for a solution of connecting users from teams and their posts (like entries in datatable). User have to see only these posts which are its or all those which created users from his groups.

My code look like this, but doesn't work properly. :( Thank you so much for any help.

$emails = array();
foreach(Auth()->user()->teams()->get() as $team) {
foreach($team->users()->get() as $user) {
array_push($emails, $user->value('email'));
}
}

I found this solution, but looks too strange. Is there any better/faster solution, please? Thank you.
foreach(Auth()->user()->teams()->get() as $team) {
foreach($team->users()->get() as $user) {
if(!in_array($user->email, $emails, true)){
array_push($emails, $user->email);
}
}
}

I'll close this since its an old issue. Feel free to open another if you still need help.