1
0
Fork 0
forked from mirror/pixelfed
pixelfed/app/Http/Controllers/DiscoverController.php

32 lines
1.1 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-05-30 03:04:26 +00:00
$following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id');
$people = Profile::inRandomOrder()->where('id', '!=', Auth::user()->profile->id)->whereNotIn('id', $following)->take(3)->get();
$posts = Status::whereHas('media')->where('profile_id', '!=', Auth::user()->profile->id)->whereNotIn('profile_id', $following)->orderBy('created_at', 'desc')->take('21')->get();
2018-05-30 03:04:26 +00:00
return view('discover.home', compact('people', 'posts'));
}
public function showTags(Request $request, $hashtag)
{
$tag = Hashtag::whereSlug($hashtag)->firstOrFail();
$posts = $tag->posts()->has('media')->orderBy('id','desc')->paginate(12);
$count = $tag->posts()->has('media')->orderBy('id','desc')->count();
return view('discover.tags.show', compact('tag', 'posts', 'count'));
}
}