Random Search laravel

1

I'm doing a random query in the users table of my application in laravel , example below:
User::inRandomOrder()->paginate(10)

It actually returns the result to me in a random way, but I need the whole record of the users table with the users_destaque = 1 column to be listed first randomly, and every record with the users_destaque = 0 column is listed afterwards also randomly, I'm waiting.

    
asked by anonymous 12.06.2017 / 22:16

1 answer

1

You should also put your main order, in this case ... ('users_destaque', 'DESC') .

Try the following, Laravel versions < 5.2:

User::orderBy('users_destaque', 'DESC')->orderByRaw("RAND()")->paginate(10);

For a version of Laravel > = 5.2 is how you were doing, with addition of the main order:

User::orderBy('users_destaque', 'DESC')->inRandomOrder()->paginate(10);
    
12.06.2017 / 22:20