filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
18.93k stars 2.93k forks source link

Spatie Translatable + FileUpload image won't work with RelationManager #12827

Closed widdydev closed 5 months ago

widdydev commented 5 months ago

Package

filament/spatie-laravel-translatable-plugin

Package Version

v3.2.80

Laravel Version

v11.7.0

Livewire Version

v3.4.12

PHP Version

PHP 8.3.0

Problem description

When I navigate to the edit page of a resource that uses a RelationManager, that inherits the activeLocale from the resource, in combination with the FileUpload('image)->image()->imageEditor() form schema I'm receiving the error: Typed property Filament\Resources\RelationManagers\RelationManager::$table must not be accessed before initialization

Bildschirmfoto 2024-05-16 um 15 23 04

Expected behavior

No error at all.

Steps to reproduce

Create 2 related models that both use the HasTranslations trait. Set up a RelationManager that uses the Translatable trait in combination with the inheritance of the activeLocale described like here.

...  
use Translatable;

#[Reactive]
public ?string $activeLocale = null;
...

This RelationshipManager will then be added to the relationships in the associated filament resource.

public static function getRelations(): array
    {
        return [
            RelationManagers\VariantsRelationManager::class,
        ];
    }

The parent resource that will use that RelationManger should have a FileUpload('image)->image()->imageEditor() field defined in the form schema.

 public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\TextInput::make('title')->required(),
                Forms\Components\FileUpload::make('image')->image()->imageEditor(),
            ]);
    }

Then navigate to the EditPage of the parent resource and change the locale via the provided LocaleSwitcher action a few times. After that hit F5 to refresh the page and immediately get the error.

This error also occurs from time to time even without refreshing the page, just by navigation around different edit pages of the parent resource.

Reproduction repository

https://github.com/widdydev/filament-translatable-image-issue

Relevant log output

No response

danharrin commented 5 months ago

I am posting this same message across all Spatie Translatable issues & PRs

Hey all! Wanted to update you on where we're at with the translatable plugin.

I really appreciate your patience while this issue has been active. While I created the plugin for the community, I've never actually had a project where I needed to use it, and that's the same for the rest of the Filament team. As such, it's the reason why the plugin hasn't had as much attention as the others, and is much more unstable: I just don't have the environment to test all the use cases, nor the motivation to make it truly great.

As such, I put out a post a month ago and asked who in the community uses the plugin and has knowledge of plugin development. Luckily, Lara Zeus and Mohamed Sabil stepped forward, who are both authors of popular Filament plugins and are trusted by the community.

We are strongly considering handing over maintenance of the plugin to those developers, for the good of the community. You can find their fork at https://github.com/lara-zeus/translatable.

Since the new developers have lots of experience with the plugin and active projects that use it, they should be able to help debug issues easier and make a much more stable experience for other users.

If their work goes well until v4 is released, we will likely retire the plugin at that point and recommend the fork as an official replacement. If it does not go as expected and the community is unhappy, then we will reconsider this decision. I am closing this for now, and if we decide to take maintenance back officially then we will probably reopen it.

The existing plugin will continue to receive security updates indefinitely. Please let me know if you have any further questions.

Many thanks, Dan

atmonshi commented 5 months ago

this an attempt to fix the issue if anyone willing to test this PR I would appreciate the feedback.

widdydev commented 5 months ago

this an attempt to fix the issue if anyone willing to test this PR I would appreciate the feedback.

Thanks @atmonshi for the attempt to fix. I've used your fork with the latest version, but unfortunately the PR did not fix the issue. Feel free to test/debug with my provided reproduction repository.

atmonshi commented 5 months ago

hey @widdydev, can you check if this will fix your issue. I cloned your repo and did get the error table must not be accessed before initialization

but after these changes it didnt appears, tried to refresh many times an go back and the error is gone :)

Screenshot 2024-05-26 at 4 44 23 AM Screenshot 2024-05-26 at 4 42 25 AM
widdydev commented 5 months ago

hey @widdydev, can you check if this will fix your issue. I cloned your repo and did get the error table must not be accessed before initialization

but after these changes it didnt appears, tried to refresh many times an go back and the error is gone :)

Screenshot 2024-05-26 at 4 44 23 AM Screenshot 2024-05-26 at 4 42 25 AM

Hi @atmonshi , thanks for your effort so far.

You're right, by adding the LocaleSwitcher to the RelationManager, the error is gone. Unfortunately this is a different usecase and is not desired in that case.

In my scenario the user selects the locale on the top of the page and all the subsequent/nested models should inherit this locale and output the values in the same locale without the need to select the locale again. According to the official docs, it is possible to achieve that by adding the reactive activeLocale attribute to the Relationship manager.

Please reopen that issue.