nicolaslopezj / searchable

A php trait to search laravel models
MIT License
2.01k stars 291 forks source link

SQLSTATE[42000]: Syntax error or access violation: 1055 #218

Closed salehasadi closed 4 years ago

salehasadi commented 4 years ago

I simply added this property to my Book model: `protected $searchable = [ /**

and then ran this simple query in my controller: dd(Book::search('test', null, true)->get());

but it throws this to me:

Illuminate \ Database \ QueryException (42000) SQLSTATE[42000]: Syntax error or access violation: 1055 'book_store.books.name' isn't in GROUP BY (SQL: select from (select books., max((case when LOWER(name) LIKE test then 150 else 0 end) + (case when LOWER(name) LIKE test% then 50 else 0 end) + (case when LOWER(name) LIKE %test% then 10 else 0 end) + (case when LOWER(description) LIKE test then 150 else 0 end) + (case when LOWER(description) LIKE test% then 50 else 0 end) + (case when LOWER(description) LIKE %test% then 10 else 0 end)) as relevance from books where books.deleted_at is null group by books.id having relevance >= 10.00 order by relevance desc) as books)

fxamauri commented 4 years ago

Hello @salehasadi, I had the same problem as you. I was able to solve it changing the strict of mysql in config/database.php to false

'mysql' => [
     // ...
    'strict' => false,
     // ...
],

I don't know if it was the best solution, but it solved my problem.

salehasadi commented 4 years ago

Hello @salehasadi, I had the same problem as you. I was able to solve it changing the strict of mysql in config/database.php to false

'mysql' => [
     // ...
    'strict' => false,
     // ...
],

I don't know if it was the best solution, but it solved my problem.

worked like a charm bro! Thanks

salehasadi commented 4 years ago

I close this issue as @fxamauri's solution made it work.