From 97869fc10090d0f85744049c1edab60dff08cf53 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Thu, 12 Jul 2018 10:37:31 -0600 Subject: [PATCH] Update SiteController --- app/Http/Controllers/SiteController.php | 30 ++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/SiteController.php b/app/Http/Controllers/SiteController.php index 31603176..e90f4789 100644 --- a/app/Http/Controllers/SiteController.php +++ b/app/Http/Controllers/SiteController.php @@ -2,11 +2,39 @@ namespace App\Http\Controllers; -use App; +use App, Auth; use Illuminate\Http\Request; +use App\{Follower, Status, User}; class SiteController extends Controller { + + public function home() + { + if(Auth::check()) { + return $this->homeTimeline(); + } else { + return $this->homeGuest(); + } + } + + public function homeGuest() + { + return view('site.index'); + } + + public function homeTimeline() + { + // TODO: Use redis for timelines + $following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id'); + $following->push(Auth::user()->profile->id); + $timeline = Status::whereIn('profile_id', $following) + ->orderBy('id','desc') + ->withCount(['comments', 'likes', 'shares']) + ->simplePaginate(10); + return view('timeline.template', compact('timeline')); + } + public function changeLocale(Request $request, $locale) { if(!App::isLocale($locale)) {