瀏覽代碼

Update Profile model, added recommendedFollowers() and keyId() methods

Daniel Supernault 7 年之前
父節點
當前提交
305fd10519
共有 1 個文件被更改,包括 32 次插入1 次删除
  1. 32 1
      app/Profile.php

+ 32 - 1
app/Profile.php

@@ -2,7 +2,7 @@
 
 
 namespace App;
 namespace App;
 
 
-use Storage;
+use Auth, Storage;
 use App\Util\Lexer\PrettyNumber;
 use App\Util\Lexer\PrettyNumber;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\SoftDeletes;
 use Illuminate\Database\Eloquent\SoftDeletes;
@@ -138,4 +138,35 @@ class Profile extends Model
     {
     {
         return $this->statuses()->whereHas('media')->count();
         return $this->statuses()->whereHas('media')->count();
     }
     }
+
+    public function recommendFollowers()
+    {
+        $follows = $this->following()->pluck('followers.id');
+        $following = $this->following()
+            ->orderByRaw('rand()')
+            ->take(3)
+            ->pluck('following_id');
+        $following->push(Auth::id());
+        $following = Follower::whereNotIn('profile_id', $follows)
+            ->whereNotIn('following_id', $following)
+            ->whereNotIn('following_id', $follows)
+            ->whereIn('profile_id', $following)
+            ->orderByRaw('rand()')
+            ->limit(3)
+            ->pluck('following_id');
+        $recommended = [];
+        foreach($following as $follow) {
+            $recommended[] = Profile::findOrFail($follow);
+        }
+
+        return $recommended;
+    }
+
+    public function keyId()
+    {
+        if($this->remote_url) {
+            return;
+        }
+        return $this->permalink('#main-key');
+    }
 }
 }