Closed tsaiyihua closed 3 years ago
my fault. sorry
my fault. sorry
Could you kindly share how you fixed this? I have exactly the same issue. Thanks!
Could you kindly share how you fixed this? I have exactly the same issue. Thanks!
In my Reproduce case.
I forget to implements Translatable in my model and use the wrong trait, the trait must be \Astrotomic\Translatable\Translatable;
The correct code for the model in this case, should be
<?php
namespace App\Models;
use Astrotomic\Translatable\Contracts\Translatable as TranslatableContract;
use Astrotomic\Translatable\Translatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class MyTest extends Model implements TranslatableContract
{
use HasFactory;
use Translatable;
public $translatedAttributes = ['name'];
public $translationModel = MyTestTranslation::class;
protected $fillable = ['display'];
}
Describe the bug While use seeder to create model with translations, it always return error with "Array to string conversion", but the same code in tinker is ok.
To Reproduce config/translatable.php
Model - MyTest.php
Model - MyTestTranslations.php
factory - MyTestFactory.php
seeder - MyTestSeeder.php
Expected behavior create data successfully
Screenshots none
Versions (please complete the following information)
Additional context This bug only happened in seeder,
Exception The thrown exception message.
Stack Trace