2018-05-26 22:49:39 +00:00
|
|
|
<?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;
|
2018-05-26 22:49:39 +00:00
|
|
|
|
|
|
|
class DiscoverController extends Controller
|
|
|
|
{
|
2018-05-30 03:04:26 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
2018-05-26 22:49:39 +00:00
|
|
|
public function home()
|
|
|
|
{
|
2018-05-30 03:04:26 +00:00
|
|
|
$following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id');
|
2018-06-01 11:13:32 +00:00
|
|
|
$people = Profile::inRandomOrder()->whereNotIn('id', $following)->take(3)->get();
|
2018-05-30 03:04:26 +00:00
|
|
|
$posts = Status::whereHas('media')->whereNotIn('profile_id', $following)->orderBy('created_at', 'desc')->take('21')->get();
|
|
|
|
return view('discover.home', compact('people', 'posts'));
|
2018-05-26 22:49:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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'));
|
|
|
|
}
|
|
|
|
}
|