laravel-translatable
laravel-translatable copied to clipboard
Package not working correctly with livewire
It's not possible to use wire.model.defer with this package in livewire
+1
+1
Syntax PHP 8+
public function mount(Blog $blog): void
{
$this->blog = $blog->loadMissing(['seo', 'translations']);
...
if ($this->blog->exists) {
$this->translations = $this->blog?->getTranslationsArray();
}
....
collect(array_keys($this->locales))->each(function ($key) {
if (empty($this->translations[$key])) {
$this->translations[$key]['title'] ??= '';
$this->translations[$key]['longtitle'] ??= '';
$this->translations[$key]['description'] ??= '';
$this->translations[$key]['content'] ??= '';
}
});
}
public function save(): void
{
$this->blog->fill($this->translations);
$this->blog->slug ??= str($this->blog->translateOrDefault('en')?->title)->slug();
$this->validated();
....
$this->blog->save();
....
}
Or use DTO https://laravel-livewire.com/docs/2.x/properties#wireable-properties