laravel-translatable
laravel-translatable copied to clipboard
Reference id is 0
I don't know this is a bug or I did not find the properly to handle the package. If the id of Post is input manually by form:
class Job extends Model implements TranslatableContract
{
use SoftDeletes, Translatable;
public $timestamps = true;
public $translatedAttributes = ['title', 'content'];
public $translationForeignKey = 'post_id';
protected $table = 'posts';
protected $primaryKey = 'id';
protected $keyType = 'string';
protected $dates = ['deleted_at'];
protected $fillable = [
'id',
'title',
'category_id',
'published',
'user_id',
];
}
then:
$input = $request->validated();
$post = Post::create($input);
The translation is excuted automatically in the same way with $post = Post::update($input) but the value of post_id cannot get properly, it always is 0, Although at that moment the new record $post was already created in DB. Although I tried:
$input['translation'] = [
session('locale') => [
'title' => $request->input('title'),
'content' => $request->input('content')
],
];
$post = Post::create($input);
But no success.
How should I overcome this situation. Thank you.
Note: Everything works properly if the id is auto increment.
Versions (please complete the following information)
- PHP: 8.1
- Database: MySQl 5.7
- Laravel: 11
- Package: Astrotomic/laravel-translatable