1
0
Fork 0
pixelfed/app/Http/Controllers/DiscoverController.php

55 lines
1.1 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
2018-09-22 05:23:16 +00:00
use App\{
Follower,
Hashtag,
Profile,
Status,
UserFilter
};
use Auth, DB, Cache;
2018-08-28 03:07:36 +00:00
use Illuminate\Http\Request;
class DiscoverController extends Controller
{
2018-05-30 03:04:26 +00:00
public function __construct()
{
2018-08-28 03:07:36 +00:00
$this->middleware('auth');
2018-05-30 03:04:26 +00:00
}
2018-09-22 05:31:21 +00:00
public function home(Request $request)
{
2018-11-09 04:14:35 +00:00
return view('discover.home');
}
public function showTags(Request $request, $hashtag)
{
2018-08-28 03:07:36 +00:00
$this->validate($request, [
'page' => 'nullable|integer|min:1|max:10',
2018-08-10 02:58:52 +00:00
]);
2018-08-28 03:07:36 +00:00
$tag = Hashtag::with('posts')
2018-08-10 02:58:52 +00:00
->withCount('posts')
->whereSlug($hashtag)
->firstOrFail();
2018-08-28 03:07:36 +00:00
$posts = $tag->posts()
2018-12-21 19:53:10 +00:00
->whereNull('url')
->whereNull('uri')
2018-11-19 04:26:52 +00:00
->whereHas('media')
2018-10-20 18:29:37 +00:00
->withCount(['likes', 'comments'])
2018-08-10 02:58:52 +00:00
->whereIsNsfw(false)
->whereVisibility('public')
2018-08-28 03:07:36 +00:00
->orderBy('id', 'desc')
2018-08-10 02:58:52 +00:00
->simplePaginate(12);
2018-11-19 04:26:52 +00:00
if($posts->count() == 0) {
abort(404);
}
2018-08-28 03:07:36 +00:00
return view('discover.tags.show', compact('tag', 'posts'));
}
}