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

Closed
profd2004 opened this issue Aug 22, 2024 · 1 comment
Closed

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/laravel-translatable@6.8.0
  2. Install spatie/laravel-data@4.8.1
  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

@spatie-bot
Copy link

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

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

2 participants