Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 2 years ago.
0

Can you not use an ENUM field in the database for these values which would allow you to do what you want.

Last updated 2 years ago.
0

Try this:

// Start query...
$query->orderByRaw("FIELD(priority, 'High', 'Medium', 'Low')");
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

That's strange.. Are you sure that last 'High' doesn't contain extra spacing or anything?

Last updated 2 years ago.
0

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()

Last updated 2 years ago.
0

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'));
Last updated 2 years ago.
0

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'))

Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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()

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.