DiscoverController.php 989 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\{
  4. Follower,
  5. Hashtag,
  6. Profile,
  7. Status,
  8. UserFilter
  9. };
  10. use Auth, DB, Cache;
  11. use Illuminate\Http\Request;
  12. class DiscoverController extends Controller
  13. {
  14. public function __construct()
  15. {
  16. $this->middleware('auth');
  17. }
  18. public function home(Request $request)
  19. {
  20. return view('discover.home');
  21. }
  22. public function showTags(Request $request, $hashtag)
  23. {
  24. $this->validate($request, [
  25. 'page' => 'nullable|integer|min:1|max:10',
  26. ]);
  27. $tag = Hashtag::with('posts')
  28. ->withCount('posts')
  29. ->whereSlug($hashtag)
  30. ->firstOrFail();
  31. $posts = $tag->posts()
  32. ->withCount(['likes', 'comments'])
  33. ->whereIsNsfw(false)
  34. ->whereVisibility('public')
  35. ->has('media')
  36. ->orderBy('id', 'desc')
  37. ->simplePaginate(12);
  38. return view('discover.tags.show', compact('tag', 'posts'));
  39. }
  40. }