1
0

SiteController.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App, Auth;
  4. use Illuminate\Http\Request;
  5. use App\{Follower, Status, User};
  6. class SiteController extends Controller
  7. {
  8. public function home()
  9. {
  10. if(Auth::check()) {
  11. return $this->homeTimeline();
  12. } else {
  13. return $this->homeGuest();
  14. }
  15. }
  16. public function homeGuest()
  17. {
  18. return view('site.index');
  19. }
  20. public function homeTimeline()
  21. {
  22. // TODO: Use redis for timelines
  23. $following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id');
  24. $following->push(Auth::user()->profile->id);
  25. $timeline = Status::whereIn('profile_id', $following)
  26. ->orderBy('id','desc')
  27. ->withCount(['comments', 'likes', 'shares'])
  28. ->simplePaginate(10);
  29. return view('timeline.template', compact('timeline'));
  30. }
  31. public function changeLocale(Request $request, $locale)
  32. {
  33. if(!App::isLocale($locale)) {
  34. return redirect()->back();
  35. }
  36. App::setLocale($locale);
  37. return redirect()->back();
  38. }
  39. }