当我使用 orderByRaw 函数时,我遇到了 Eloquent/QueryBuilder 的问题,我得到了异常列不存在,但该列已经存在于数据库中。
异常(exception)情况:
SQLSTATE[42883]: Undefined function: 7 ERROR: function field(integer, integer) does not exist
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
数据库中的状态列是整数。 这是我的代码:
$orderedStatuses = implode(',', [4]);
$users->orderByRaw(\DB::raw("FIELD(status, $orderedStatuses)"));
...另外,如果我使用 users.status,我也会遇到同样的错误。
有人可以帮助我吗?
谢谢
最佳答案
你混合了这两种方法。
$users->orderBy(\DB::raw("FIELD(status, $orderedStatuses)"));
或者
$users->orderByRaw("FIELD(status, $orderedStatuses)");
关于database - Laravel 5,使用字段和列的 orderByRaw 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44294107/