1

I am developing a web admin panel using Laravel Nova.

I'm getting an issue about Japanese character saving to Database.

My environment is as follows:

  • Laravel Version: 7.14.1
  • Nova Version: 3.6.0
  • PHP Version: 7.3.11
  • Database Driver & Version: MySQL 5.7.22
  • Operating System and Version: Amazon Linux release 2
  • Browser type and version: Chrome 81.0.4044.138

My scenario is as follows:

  1. Create databases (It set UTF8mb4 Unicode collation)
  2. Create Model & Migration file (Table called "Area".)

    php artisan make:model Area --migration
    
  3. Modify the "area" migration file. Create 4 columns (id, name, created_at, updated_at)

  4. Defining resource in the Nova admin panel.

    php artisan nova:resource Area
    
  5. Modify Nova's Resource file. adding this script to file.

    public function fields(Request $request){
        return [
            ID::make()->sortable(),
    
            Text::make('Name')
               ->sortable()
               ->rules('required', 'max:24')
        ];
    }
    
  6. Insert Japanese data from Nova admin panel. I typed the Japanese word "北海道". enter image description here

  7. After clicking the update button, the data stored in the database will be garbled. I also want to say that the charset of garbled characters was "iso-8859-1". enter image description here

That's my issue. I want to operate and manage Japanese data in Nova's admin panel!

Ofcourse, I was able to find some helpful questions from Stack overflow. For example, Laravel 5 Model $cats to array utf-8 JSON_UNESCAPED_UNICODE . It was told how to override the "toJson" function in the model, but It couldn't get involved with Laravel Nova.

When faced with such a multilingual problem, many of the Japanese references pointed out "To disable Unicode escaping in Laravel's json response.". But it didn't work too.

So problem is "Stop escaping Unicode in json response in Laravel Nova". But I'm not sure which file or which function to modify....

If anyone knows a solution, I would be grateful if you could give me a hint or solution.

Thank you.

  • Those `å��æµ·é��` characters represent _CP1252_ (or _ISO-8859-1_) appearance of UTF-8 bytes of the `北海道` string. Maybe a discrepancy in MySQL client and server encoding? – JosefZ Jun 13 '20 at 18:16
  • MySQL client and server have the same UTF-8 encoding. – Meteorstrikes Jun 14 '20 at 07:46
  • You are surely suffering from [double encoding](https://stackoverflow.com/a/38363567/3439404), mentioned at [MySQL Charset/Collate](http://mysql.rjweb.org/doc.php/charcoll) as well. – JosefZ Jun 14 '20 at 09:47
  • Yes, just I want to disable escaping unicode in JSON encode... – Meteorstrikes Jun 14 '20 at 16:45

0 Answers0