1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
| $result = User::select(['id as user_id', 'parent_id']) ->withDepth() ->having('depth', '=', 1) ->get() ->toArray(); print_r($result);
Array ( [0] => Array ( [user_id] => 4 [parent_id] => 1 [depth] => 1 )
[1] => Array ( [user_id] => 5 [parent_id] => 1 [depth] => 1 )
[2] => Array ( [user_id] => 6 [parent_id] => 1 [depth] => 1 )
[3] => Array ( [user_id] => 7 [parent_id] => 2 [depth] => 1 )
[4] => Array ( [user_id] => 8 [parent_id] => 2 [depth] => 1 )
[5] => Array ( [user_id] => 9 [parent_id] => 2 [depth] => 1 )
[6] => Array ( [user_id] => 10 [parent_id] => 3 [depth] => 1 )
[7] => Array ( [user_id] => 11 [parent_id] => 3 [depth] => 1 )
[8] => Array ( [user_id] => 12 [parent_id] => 3 [depth] => 1 )
)
|