浏览代码

Update follower model, add new methods

Daniel Supernault 7 年之前
父节点
当前提交
95dcf8f7b3
共有 1 个文件被更改,包括 28 次插入1 次删除
  1. 28 1
      app/Follower.php

+ 28 - 1
app/Follower.php

@@ -6,5 +6,32 @@ use Illuminate\Database\Eloquent\Model;
 
 class Follower extends Model
 {
-    //
+    public function actor()
+    {
+      return $this->belongsTo(Profile::class, 'profile_id', 'id');
+    }
+
+    public function target()
+    {
+      return $this->belongsTo(Profile::class, 'following_id', 'id');
+    }
+
+    public function profile()
+    {
+      return $this->belongsTo(Profile::class, 'following_id', 'id');
+    }
+
+    public function toText()
+    {
+      $actorName = $this->actor->username;
+      return "{$actorName} " . __('notification.startedFollowingYou');
+    }
+
+    public function toHtml()
+    {
+      $actorName = $this->actor->username;
+      $actorUrl = $this->actor->url();
+      return "<a href='{$actorUrl}' class='profile-link'>{$actorName}</a> " .
+          __('notification.startedFollowingYou');
+    }
 }