Trying to order my table by newest Date first, then the status. The Status can be (New, In Review, Declined, Closed) and Status is an enum field in the database.
I've tried several things with no success. This is the closest I've got with this code. I'm new to Laravel so not sure how to do this.
$inquiries = Inquiry::all()->sortByDesc('created_at')->sortByDesc('Status')->values();
That produces this:
-------------------------------------------------------------- | Name | Created At | Status | -------------------------------------------------------------- | Richard | 05/02/2020 | New | -------------------------------------------------------------- | James | 05/02/2020 | New | -------------------------------------------------------------- | Christine | 04/16/2020 | Declined | -------------------------------------------------------------- | Charles | 04/14/2020 | New | -------------------------------------------------------------- | Judy | 03/13/2020 | In Review | -------------------------------------------------------------- | Paul | 01/12/2020 | New | --------------------------------------------------------------
I would like it to look like this where it's sorted by Date, with the newest Date first, then with status = "New". I would like it to look like this:
-------------------------------------------------------------- | Name | Created At | Status | -------------------------------------------------------------- | Richard | 05/02/2020 | New | -------------------------------------------------------------- | James | 05/02/2020 | New | -------------------------------------------------------------- | Charles | 04/14/2020 | New | -------------------------------------------------------------- | Paul | 01/12/2020 | New | -------------------------------------------------------------- | Christine | 04/16/2020 | Declined | -------------------------------------------------------------- | Judy | 03/13/2020 | In Review | --------------------------------------------------------------
$inquiries = Inquiry::orderBy('created_at','desc')->orderBy('Status','desc')->get();
$inquiries = Inquiry::orderBy('Status','desc')->orderBy('created_at','desc')->get();