Merge pull request #93 from neilalexander/patch-2

Use inRandomOrder instead of orderByRaw in Discover page
This commit is contained in:
daniel 2018-06-01 16:34:46 -06:00 committed by GitHub
commit 7c4a383a65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -43,8 +43,8 @@ class SeedFollows extends Command
for ($i=0; $i < $limit; $i++) {
try {
$actor = Profile::orderByRaw('rand()')->firstOrFail();
$target = Profile::orderByRaw('rand()')->firstOrFail();
$actor = Profile::inRandomOrder()->firstOrFail();
$target = Profile::inRandomOrder()->firstOrFail();
$follow = new Follower;
$follow->profile_id = $actor->id;

View file

@ -16,7 +16,7 @@ class DiscoverController extends Controller
public function home()
{
$following = Follower::whereProfileId(Auth::user()->profile->id)->pluck('following_id');
$people = Profile::whereNotIn('id', $following)->orderByRaw('rand()')->take(3)->get();
$people = Profile::inRandomOrder()->whereNotIn('id', $following)->take(3)->get();
$posts = Status::whereHas('media')->whereNotIn('profile_id', $following)->orderBy('created_at', 'desc')->take('21')->get();
return view('discover.home', compact('people', 'posts'));
}