Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel and package spatie/laravel-translatable -> Make search query for special character

I use the package Spatie/laravel-translatable to store my translated data in json in the database.

I have a column title :

{
  "fr":"L\u2019\u00e9quipe",
  "en":"Team",
  "de":"Team"
}

As you can see, with the package, special characters are transformed into unicode.

When I want to search, it does not work (it's logical, because I'm looking for the word équipe but in the database it says \u00e9quipe)

$search = $request->get('search')

Events::where('title', 'LIKE', '%' . $search . '%')->published()->get();

How to search through Unicode for it to work?

Thank you

like image 724
Jeremy Avatar asked Oct 20 '25 02:10

Jeremy


1 Answers

in the Spatie\Translatable\HasTranslations trait use $this->attributes[$key] = json_encode($translations, JSON_UNESCAPED_UNICODE);

instead of $this->attributes[$key] = $this->asJson($translations);

like image 108
Taha Elkholy Avatar answered Oct 21 '25 16:10

Taha Elkholy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!