1$users = App\Models\User::all();
2
3$names = $users->reject(function ($user) {
4 return $user->active === false;
5})
6->map(function ($user) {
7 return $user->name;
8});
1use App\Models\User;
2
3$users = $users->intersect(User::whereIn('id', [1, 2, 3])->get());
1$users = App\Models\User::where('active', 1)->get();
2
3foreach ($users as $user) {
4 echo $user->name;
5}
1use App\Models\User;
2
3$users = $users->diff(User::whereIn('id', [1, 2, 3])->get());