diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 78506fc..61bcacf 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -6,9 +6,4 @@
./tests/
-
-
- src/
-
-
diff --git a/src/Traits/Follower.php b/src/Traits/Follower.php
index 78af977..b17b022 100644
--- a/src/Traits/Follower.php
+++ b/src/Traits/Follower.php
@@ -153,6 +153,7 @@ public function attachFollowStatus($followables, callable $resolver = null)
$item = $followed->where('followable_id', $followable->getKey())
->where('followable_type', $followable->getMorphClass())
->first();
+ $followable->setAttribute('has_followed', !!$item);
$followable->setAttribute('followed_at', $item ? $item->created_at : null);
$followable->setAttribute('follow_accepted_at', $item ? $item->accepted_at : null);
}
diff --git a/tests/FeatureTest.php b/tests/FeatureTest.php
index 6420d4c..511726f 100644
--- a/tests/FeatureTest.php
+++ b/tests/FeatureTest.php
@@ -232,9 +232,16 @@ function () use ($user1, $users) {
$users = $users->toArray()['data'];
$this->assertNull($users[0]['followed_at']);
+ $this->assertFalse($users[0]['has_followed']);
+
$this->assertNotNull($users[1]['followed_at']);
+ $this->assertTrue($users[1]['has_followed']);
+
$this->assertNotNull($users[2]['followed_at']);
+ $this->assertTrue($users[2]['has_followed']);
+
$this->assertNotNull($users[3]['followed_at']);
+ $this->assertTrue($users[3]['has_followed']);
// cursor paginator
$users = User::cursorPaginate();
@@ -242,17 +249,31 @@ function () use ($user1, $users) {
$users = $users->toArray()['data'];
$this->assertNull($users[0]['followed_at']);
+ $this->assertFalse($users[0]['has_followed']);
+
$this->assertNotNull($users[1]['followed_at']);
+ $this->assertTrue($users[1]['has_followed']);
+
$this->assertNotNull($users[2]['followed_at']);
+ $this->assertTrue($users[2]['has_followed']);
+
$this->assertNotNull($users[3]['followed_at']);
+ $this->assertTrue($users[3]['has_followed']);
// cursor
$users = User::cursor();
$users = $user1->attachFollowStatus($users)->toArray();
$this->assertNull($users[0]['followed_at']);
+ $this->assertFalse($users[0]['has_followed']);
+
$this->assertNotNull($users[1]['followed_at']);
+ $this->assertTrue($users[1]['has_followed']);
+
$this->assertNotNull($users[2]['followed_at']);
+ $this->assertTrue($users[2]['has_followed']);
+
$this->assertNotNull($users[3]['followed_at']);
+ $this->assertTrue($users[3]['has_followed']);
// with custom resolver
$users = \collect(['creator' => $user2], ['creator' => $user3], ['creator' => $user4]);