laravel-orm

Laravel - randomly select n number of rows containing same value in certain column after applying 'order by'

▼魔方 西西 提交于 2020-02-06 09:27:13
问题 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

Laravel - randomly select n number of rows containing same value in certain column after applying 'order by'

烂漫一生 提交于 2020-02-06 09:23:30
问题 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