I can make the following call
$userGroups = Auth::user()->getGroups();
The above will output something like the following
array:10 [▼
0 => "Admin"
1 => "TeamA"
3 => "USA"
4 => "security"
9 => "Users"
]
So I can see that I am a member of all of the above groups. I also have a clients table, and one of the fields of this table is team. An example client is like so
#attributes: array:11 [▼
"id" => "3"
"clientName" => "Some Client"
"contactEmail" => ""
"team" => "TeamA"
"created_at" => "2016-07-04 15:08:15"
"updated_at" => "2016-07-04 15:08:15"
]
What I am trying to do is get all clients which have a team which is part of the logged in users groups. So you can see that I am apart of TeamA therefor I want all clients that have a team value of TeamA. I was thinking something along the lines of this
$clients = Client::where('team', in_array('TeamA', $userGroups))->get();
The above returns an empty result set, but hopefully it demonstrates what I am after.
How can I achieve this?
Thanks
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire