Issue
Need to order (sort) content in two way.
1: field "featured" can be 1 or 0 (default), need to show first content with featured "1" value,
->order(['featured DESC']);
2: field "featured_start" can be Y-m-d DATE or NULL (default), need to show first content with date, than with NULL value.
Like this
-| featured | featured_start | created |-
-----------------------------------------------------
-| 1 | 2015-12-24 | 2015-12-24 10:06:07 |-
-| 1 | 2015-12-23 | 2015-12-22 09:01:29 |-
-| 1 | NULL | 2015-12-24 09:01:29 |-
-| 0 | NULL | 2015-12-24 10:01:29 |-
-| 0 | NULL | 2015-12-20 20:20:45 |-
-----------------------------------------------------
Thanks.
Solution
SOLVED
->order([
'featured DESC',
'(CASE WHEN featured_start IS NULL THEN 1 ELSE 0 END),
'featured_start DESC',
'created DESC
]);
This returns a complex sorted data. Latest featured users are always at the top, followed by other users.
When the user subscription expires, the application via cron sets the value 0 in the "featured" field, and NULL in the "featured_start" field.
Answered By - Salines
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.