Error

When writing a test code using sqlite's in-memory function with Laravel, I got the following sql syntax error. SQLSTATE[HY000]: General error: 1 no such function: FIELD (SQL: select * from ... by FIELD(id, 1) limit 10000 offset 0)

Solution

if (env('DB_CONNECTION') === 'mysql') { $this->query->orderByRaw('FIELD(' ...')'); }