I have created a two table named Team and team_user. Here is the Schema of the both table
Team Table
---------------------------------
| id | team_name | user_id |
---------------------------------
| 1 | Developer | 5 |
| 2 | Designer | 6 |
| 3 | Test | 7 |
| 4 | Test 2 | 8 |
---------------------------------
Team_User Table
-------------------------------------------------
| id | team_id | tl_id | user_id |
-------------------------------------------------
| 1 | 1 | 5 | 25 |
| 2 | 2 | 6 | 35 |
| 3 | 2 | 7 | 12 |
| 4 | 3 | 8 | 13 |
-------------------------------------------------
tl_id (Team Leader User ID) user_id (User ID of user who is under Team leader)
A Team leader can have multiple user under him. I want to show All the post of his team member in Team Leader view.
So for e.g if Team Leader named abc has a member named def under him and Another person named ghi is under def. So i want to show all post of def and ghi under abc Leaders view.
Till now i have done this -
$user = auth()->user();
$teams = DB::table('team_user')->where('tl_id', $user->id)->get();
$tl = array();
foreach ($teams as $team) {
$tl[] = $team->user_id;
}
$tl[] = auth()->user()->id;
$posts = DB::table('post')->where('status',1)->Where(function ($query) use($tl) {
for ($i = 0; $i < count($tl); $i++){
$query->orwhere('user_id', '=', $tl[$i]);
}
})->get();
From above code i can only get the post list of def under abc. How can i get the post ghi too and so on under him?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire