Skip to content

UTF-8 Encoding Error with Arabic Text in HasMany Relationship #6920

@d-shannon

Description

@d-shannon
  • Laravel Version: 12.32.5
  • Nova Version: 5.7.5
  • PHP Version: 8.4
  • Database Driver & Version: MySQL (utf8mb4_unicode_ci collation)
  • Operating System and Version: Laravel Vapor / php-8.4:al2-arm

Description:

UTF-8 encoding error occurs when viewing a User resource with HasMany relationship containing Arabic text. Error message: "Malformed UTF-8 characters, possibly incorrectly encoded" in /vendor/laravel/framework/src/Illuminate/Http/JsonResponse.php:89

Individual Email resources display correctly, but the HasMany relationship table fails to render. Database uses utf8mb4_unicode_ci collation, and json_encode(User::with('emails')->find($id)->toArray()) works successfully in direct Laravel tests, which appears to indicate the issue is specific to Nova's HasMany serialization.

Detailed steps to reproduce the issue on a fresh Nova installation:

  1. Create a MySQL database with utf8mb4_unicode_ci collation
  2. Create a users table and emails table with user_id foreign key
  3. Add subject (varchar) and body (mediumtext) fields to emails table with utf8mb4_unicode_ci collation
  4. Create User and Email models with standard HasMany/BelongsTo relationships
  5. Create Nova resources for User and Email
  6. In User Nova resource, add: HasMany::make('Emails')
  7. Insert email records with Arabic text in subject field
  8. Visit individual email resource in Nova - works correctly
  9. Visit user resource in Nova to view HasMany emails relationship - encoding error occurs
  10. Verify json_encode(User::with('emails')->find($id)->toArray()) works in tinker/artisan command

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions