From 305fd105191d7b3dd6de9a1737755a41c56f7ec6 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 9 Aug 2018 20:10:16 -0600 Subject: [PATCH] Update Profile model, added recommendedFollowers() and keyId() methods --- app/Profile.php | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/app/Profile.php b/app/Profile.php index 91475ca7d..4192da0f8 100644 --- a/app/Profile.php +++ b/app/Profile.php @@ -2,7 +2,7 @@ namespace App; -use Storage; +use Auth, Storage; use App\Util\Lexer\PrettyNumber; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\SoftDeletes; @@ -138,4 +138,35 @@ class Profile extends Model { 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'); + } }