diff --git a/src/Group.php b/src/Group.php index c8b75a5..5e619b2 100644 --- a/src/Group.php +++ b/src/Group.php @@ -26,6 +26,13 @@ class Group implements Arrayable { } public function members(): MemberCollection { + $members = Nami::membersOf($this->id); + + return MemberCollection::make(function() use ($members) { + foreach ($members as $member) { + yield $this->member($member['id']); + } + }); return new MemberCollection(Nami::membersOf($this->id)->map(function($member) { return $this->member($member['id']); })); diff --git a/src/MemberCollection.php b/src/MemberCollection.php index fa23d0d..edb0a88 100644 --- a/src/MemberCollection.php +++ b/src/MemberCollection.php @@ -2,9 +2,9 @@ namespace Zoomyboy\LaravelNami; -use Illuminate\Support\Collection; +use Illuminate\Support\LazyCollection; -class MemberCollection extends Collection { +class MemberCollection extends LazyCollection { public static function fromOverview($items) { $self = new self($items); diff --git a/tests/Unit/PullMemberTest.php b/tests/Unit/PullMemberTest.php index 25793ec..00f2079 100644 --- a/tests/Unit/PullMemberTest.php +++ b/tests/Unit/PullMemberTest.php @@ -100,9 +100,10 @@ class PullMemberTest extends TestCase Nami::login(); - $member = Nami::group(103)->members(); - $this->assertSame($values[0], $member->get(0)->toArray()[$key]); - $this->assertSame($values[1], $member->get(1)->toArray()[$key]); + $members = Nami::group(103)->members(); + foreach ($members as $i => $m) { + $this->assertSame($values[$i], $m->toArray()[$key]); + } Http::assertSentCount(6); }