DiscoverController.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Follower;
  4. use App\Hashtag;
  5. use App\Profile;
  6. use App\Status;
  7. use App\UserFilter;
  8. use Auth;
  9. use Illuminate\Http\Request;
  10. class DiscoverController extends Controller
  11. {
  12. public function __construct()
  13. {
  14. $this->middleware('auth');
  15. }
  16. public function home()
  17. {
  18. $pid = Auth::user()->profile->id;
  19. $following = Follower::whereProfileId($pid)
  20. ->pluck('following_id');
  21. $filtered = UserFilter::whereUserId($pid)
  22. ->whereFilterableType('App\Profile')
  23. ->whereIn('filter_type', ['mute', 'block'])
  24. ->pluck('filterable_id');
  25. $following = $following->push($filtered);
  26. $people = Profile::inRandomOrder()
  27. ->where('id', '!=', $pid)
  28. ->whereNotIn('id', $following)
  29. ->take(3)
  30. ->get();
  31. $posts = Status::whereHas('media')
  32. ->where('profile_id', '!=', $pid)
  33. ->whereNotIn('profile_id', $following)
  34. ->orderBy('created_at', 'desc')
  35. ->simplePaginate(21);
  36. return view('discover.home', compact('people', 'posts'));
  37. }
  38. public function showTags(Request $request, $hashtag)
  39. {
  40. $this->validate($request, [
  41. 'page' => 'nullable|integer|min:1|max:10',
  42. ]);
  43. $tag = Hashtag::with('posts')
  44. ->withCount('posts')
  45. ->whereSlug($hashtag)
  46. ->firstOrFail();
  47. $posts = $tag->posts()
  48. ->whereIsNsfw(false)
  49. ->whereVisibility('public')
  50. ->has('media')
  51. ->orderBy('id', 'desc')
  52. ->simplePaginate(12);
  53. return view('discover.tags.show', compact('tag', 'posts'));
  54. }
  55. }