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

59 lines
1.4 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
2018-05-30 03:04:26 +00:00
use App\{Hashtag, Follower, Profile, Status, StatusHashtag};
use Auth;
class DiscoverController extends Controller
{
2018-05-30 03:04:26 +00:00
public function __construct()
{
$this->middleware('auth');
}
public function home()
{
2018-08-10 02:58:52 +00:00
$pid = Auth::user()->profile->id;
$following = Follower::whereProfileId($pid)
->pluck('following_id');
$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);
2018-05-30 03:04:26 +00:00
return view('discover.home', compact('people', 'posts'));
}
public function showTags(Request $request, $hashtag)
{
2018-08-10 02:58:52 +00:00
$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'));
}
}