Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

translatable fields shows up as array in spatie/laravel-data DTO object #455

Open
profd2004 opened this issue Aug 22, 2024 · 0 comments
Open

Comments

@profd2004
Copy link

✏️ Describe the bug
Adding the string type of a spatie/laravel-translatable property causes a must be of type ?string, array given, called in /var/www/html/vendor/spatie/laravel-data/src/Resolvers/DataFromArrayResolver.php on line 95 error.

↪️ To Reproduce

  1. Install spatie/[email protected]
  2. Install spatie/[email protected]
  3. DTO
<?php

namespace App\DataTransferObjects;

use Spatie\LaravelData\Data;

#[TypeScript]
final class LearningTopicData extends Data
{
    public function __construct(
        public int $id,
        public string $title,
        public string $content,
      ) {}
}

4: Eloquent Model

<?php

namespace App\Models;

use Spatie\Translatable\HasTranslations;

class LearningTopic extends Model
{
   use HasTranslations;

    public array $translatable = [
        'title',
        'content',
    ];
}
  1. Use DTO in a controller: LearningTopicData::collect(LearningTopic::latest()->get()); Translatable fields are coming through as an array instead of a string:
Screenshot 2024-08-22 at 9 28 56 AM

✅ Expected behavior
Translatable fields should be a string.

🖥️ Versions

Laravel: 11.21.0
Laravel Data: 4.8.1
Laravel Translatable: 6.8.0
PHP: 8.3.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant