mpociot / teamwork

User to Team associations with invitation system for the Laravel 5 Framework
MIT License
1.07k stars 170 forks source link

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

Closed jadamec closed 4 years ago

jadamec commented 5 years ago

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); } } }

okaufmann commented 4 years ago

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