Can you not use an ENUM field in the database for these values which would allow you to do what you want.
Try this:
// Start query...
$query->orderByRaw("FIELD(priority, 'High', 'Medium', 'Low')");
stidges said:
Try this:
// Start query... $query->orderByRaw("FIELD(priority, 'High', 'Medium', 'Low')");
This works...however a strange error..below is the output
Output: High High Medium Low High <----------this one should go up with the High groups
That's strange.. Are you sure that last 'High' doesn't contain extra spacing or anything?
stidges said:
That's strange.. Are you sure that last 'High' doesn't contain extra spacing or anything?
Ohh..just found out..it doesn't work..there is no ordering happening itself
this is my code: finding()->select('vulnerability','impact','risk_rating')->orderByRaw("FIELD('risk_rating', 'High', 'Medium', 'Low')")->get()
Try removing the select, and the risk_rating shouldn't be quoted
finding()->orderByRaw("FIELD(risk_rating, 'High', 'Medium', 'Low')")->get(array('vulnerability','impact','risk_rating'));
stidges said:
Try removing the select:
finding()->orderByRaw("FIELD('risk_rating', 'High', 'Medium', 'Low')")->get(array('vulnerability','impact','risk_rating'));
No..still the same.<br/>
$project->finding()->orderByRaw("FIELD('risk_rating', 'High', 'Medium', 'Low')")->get(array('vulnerability','impact','risk_rating'))
Sorry, I did an edit later. It's the quoting of risk_rating that is the problem, it will interpret it as a string instead of the column name. Try removing it or quoting it with back quotes
stidges said:
Sorry, I did an edit later. It's the quoting of risk_rating that is the problem, it will interpret it as a string instead of the column name. Try removing it or quoting it with back quotes
Yo \m/ thanks man..works like charm
Here's the code: $project->inding()->select('vulnerability','impact','risk_rating')->orderByRaw("FIELD(risk_rating, "High", "Medium", "Low")")->get()
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community