Open martinbean opened 6 years ago
I just created a trait to accomplish this: https://gist.github.com/andreshg112/b359089878bdb2269321838d8921f429
This syntax is only supported by MySQL.
The other databases require a different solution: https://stackoverflow.com/a/1310188/4848587
@staudenmeir It’s a good job queries are crafted by database-specific grammar classes under the hood, then…
Could an order by field method by added to Eloquent? Most relational databases allow sorting a field by values, i.e. in MySQL:
I could use
orderByRaw()
for this, but there are a couple of issues:FIELD()
function (i.e. SQLite), so if the current database connection is using the SQLIte driver then the query builder should probably throw a “this feature not available” exception.Usage-wise, I see it looking like this: