Use unaccent PostgreSQL function within Laravel Eloquent Query

2.1k Views Asked by At

I'm not able to use the pgsql extension unaccent while trying to retrieve records from a database.

I set up a dynamic search in my application that sends, with Ajax, what the user types in a field, and also what field was selected. I replace every accent in the string with a javascript function before sending it to my controller.

My problem is that I don't know how to make postgre understand that it should ignore accents.

I tried to use Eloquent's whereRaw to use the unaccent (that I activated) function, with no success.

->whereRaw("unaccent(".$request->field.") ILIKE '".$request->search."'")
1

There are 1 best solutions below

0
Vadims On

Open PostgreSQL, select database and do this command:

CREATE EXTENSION unaccent;

$query->whereRaw("unaccent(".$request->field.") ilike unaccent('%".$request->search."%')");