1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-26 01:36:43 +00:00
pixelfed/app/Http/Controllers/DiscoverController.php

53 lines
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-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'));
}
}