In my Laravel project, in the database table ads, I have  the following structure :
id | col1 | col2
col2 has values like topad, bump,urgent along with empty value. I want to take all the rows from the ads table and sort them alphabetically based on col2 in descending order.
So I used:
Ads::orderBy('col2','DESC')->get()
Now I have 2 conditions to be applied on the query.
1st condition :  Suppose there are 4 rows with topad in col2, 5 rows with urgent in col2, 6 rows with bump in col2 and 7 rows  each with an empty value in col2 . So  rows with urgent in col2 will appear 1st, with topad in col2 will appear 2nd and with bump in col2 will appear 3rd and with empty values in col2 will appear 4th.  Now I need to randomize the rows' order within each set. For example , rows with topad in col2 may have the ids 1,2,3,4. I want to randomize these rows (which may result into for example 4,2,1,3). But they will appear before rows containing topad in col2. Same is true for topad and bump row sets and rows containing any empty  value in col2.
So the query becomes :
Ads::orderBy('col2','DESC')->inRandomOrder()->get(); 
2nd condition : Suppose rows are ordered by col2 values. But from each set of rows containing same value in col2, I need n number of rows from those that have non-empty value in col2 i.e. randomly I need  n rows from urgented rows, n from topaded rows, n from bumped rows  and all from emptyed rows. 
How to write the query then ?
 
     
    