1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-25 01:05:36 +00:00
pixelfed/app/Http/Controllers/DiscoverController.php
2018-08-30 22:18:43 -06:00

69 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers;
use App\Follower;
use App\Hashtag;
use App\Profile;
use App\Status;
use App\UserFilter;
use Auth;
use Illuminate\Http\Request;
class DiscoverController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function home()
{
$pid = Auth::user()->profile->id;
$following = Follower::whereProfileId($pid)
->pluck('following_id');
$filtered = UserFilter::whereUserId($pid)
->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id');
$following = $following->push($filtered);
$people = Profile::inRandomOrder()
->where('id', '!=', $pid)
->whereNotIn('id', $following)
->take(3)
->get();
$posts = Status::whereHas('media')
->where('profile_id', '!=', $pid)
->whereNotIn('profile_id', $following)
->orderBy('created_at', 'desc')
->simplePaginate(21);
return view('discover.home', compact('people', 'posts'));
}
public function showTags(Request $request, $hashtag)
{
$this->validate($request, [
'page' => 'nullable|integer|min:1|max:10',
]);
$tag = Hashtag::with('posts')
->withCount('posts')
->whereSlug($hashtag)
->firstOrFail();
$posts = $tag->posts()
->whereIsNsfw(false)
->whereVisibility('public')
->has('media')
->orderBy('id', 'desc')
->simplePaginate(12);
return view('discover.tags.show', compact('tag', 'posts'));
}
}