Astrotomic / laravel-translatable

A Laravel package for multilingual models
https://docs.astrotomic.info/laravel-translatable/
MIT License
1.23k stars 156 forks source link

Package not working correctly with livewire #236

Open RolandVerner opened 3 years ago

RolandVerner commented 3 years ago

It's not possible to use wire.model.defer with this package in livewire

CrazyBoy49z commented 2 years ago

+1

MohmmedAshraf commented 2 years ago

+1

CrazyBoy49z commented 1 year ago

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