laravel-translatable icon indicating copy to clipboard operation
laravel-translatable copied to clipboard

Package not working correctly with livewire

Open rolandverner opened this issue 3 years ago • 3 comments

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

rolandverner avatar Jul 28 '21 14:07 rolandverner

+1

CrazyBoy49z avatar Apr 27 '22 19:04 CrazyBoy49z

+1

MohmmedAshraf avatar Jun 23 '22 10:06 MohmmedAshraf

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

CrazyBoy49z avatar Nov 12 '22 12:11 CrazyBoy49z