diff --git a/app/Http/Controllers/DiscoverController.php b/app/Http/Controllers/DiscoverController.php index 9dd12c44..a8459b37 100644 --- a/app/Http/Controllers/DiscoverController.php +++ b/app/Http/Controllers/DiscoverController.php @@ -3,13 +3,22 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use App\{Hashtag, Status, StatusHashtag}; +use App\{Hashtag, Follower, Profile, Status, StatusHashtag}; +use Auth; class DiscoverController extends Controller { + public function __construct() + { + $this->middleware('auth'); + } + public function home() { - return view('discover.home'); + $following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id'); + $people = Profile::whereNotIn('id', $following)->orderByRaw('rand()')->take(3)->get(); + $posts = Status::whereHas('media')->whereNotIn('profile_id', $following)->orderBy('created_at', 'desc')->take('21')->get(); + return view('discover.home', compact('people', 'posts')); } public function showTags(Request $request, $hashtag)