Skip to content

Commit 5810722

Browse files
authored
Update Followable.php
1 parent 7bfee30 commit 5810722

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Followable.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public function followings()
190190
)->withPivot('accepted_at')->withTimestamps()->using(UserFollower::class);
191191
}
192192

193-
public function attachFollowStatus($followables)
193+
public function attachFollowStatus($followables, callable $resolver = null)
194194
{
195195
$returnFirst = false;
196196

@@ -214,7 +214,10 @@ public function attachFollowStatus($followables)
214214

215215
$followed = $this->followings()->wherePivot('accepted_at', '!=', null)->pluck('following_id');
216216

217-
$followables->map(function (Model $followable) use ($followed) {
217+
$followables->map(function (Model $followable) use ($followed, $resolver) {
218+
$resolver = $resolver ?? fn ($m) => $m;
219+
$followable = $resolver($followable);
220+
218221
if (\in_array(Followable::class, \class_uses($followable))) {
219222
$followable->setAttribute('has_followed', $followed->has($followable->getKey()));
220223
}

0 commit comments

Comments
 (0)