DiscoverController.php 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. ->whereHas('media')
  33. ->withCount(['likes', 'comments'])
  34. ->whereIsNsfw(false)
  35. ->whereVisibility('public')
  36. ->orderBy('id', 'desc')
  37. ->simplePaginate(12);
  38. if($posts->count() == 0) {
  39. abort(404);
  40. }
  41. return view('discover.tags.show', compact('tag', 'posts'));
  42. }
  43. }