pixelfed/app/Http/Controllers/DiscoverController.php

69 lines
1.7 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
2018-08-28 03:07:36 +00:00
use App\Follower;
use App\Hashtag;
use App\Profile;
use App\Status;
2018-08-31 04:18:43 +00:00
use App\UserFilter;
2018-05-30 03:04:26 +00:00
use Auth;
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
}
public function home()
{
2018-08-28 03:07:36 +00:00
$pid = Auth::user()->profile->id;
2018-08-10 02:58:52 +00:00
2018-08-28 03:07:36 +00:00
$following = Follower::whereProfileId($pid)
2018-08-10 02:58:52 +00:00
->pluck('following_id');
2018-08-31 04:18:43 +00:00
$filtered = UserFilter::whereUserId($pid)
->whereFilterableType('App\Profile')
->whereIn('filter_type', ['mute', 'block'])
->pluck('filterable_id');
2018-08-31 04:58:57 +00:00
$following->push($pid);
$following->push($filtered);
2018-08-31 04:18:43 +00:00
2018-08-28 03:07:36 +00:00
$people = Profile::inRandomOrder()
2018-08-10 02:58:52 +00:00
->whereNotIn('id', $following)
->take(3)
->get();
2018-08-28 03:07:36 +00:00
$posts = Status::whereHas('media')
2018-08-10 02:58:52 +00:00
->where('profile_id', '!=', $pid)
->whereNotIn('profile_id', $following)
->orderBy('created_at', 'desc')
->simplePaginate(21);
2018-08-28 03:07:36 +00:00
return view('discover.home', compact('people', 'posts'));
}
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-08-10 02:58:52 +00:00
->whereIsNsfw(false)
->whereVisibility('public')
->has('media')
2018-08-28 03:07:36 +00:00
->orderBy('id', 'desc')
2018-08-10 02:58:52 +00:00
->simplePaginate(12);
2018-08-28 03:07:36 +00:00
return view('discover.tags.show', compact('tag', 'posts'));
}
}