kongulov / nova-tab-translatable

This package contains a NovaTabTranslatable class you can use to make any Nova field type translatable with tabs.
MIT License
79 stars 17 forks source link

Slug preview does not work with multiple tabs instances #44

Closed fsavina-akqa closed 3 months ago

fsavina-akqa commented 4 months ago

Hello, thanks for this useful package.

I have a model with multiple instances of NovaTabTranslatable and I get a 404 error when the slug preview is getting loaded.

The reason why this is happening is because this foreach cycle should terminate when the field is found. Otherwise the following iterations will overwrite the value of $field with null.

// Kongulov\NovaTabTranslatable\Http\Controllers\FieldPreviewController, line 43

foreach ($tabs as $tab) {
  $field = collect($tab->data)->first(function($field) use ($request){
    return isset($field->attribute) &&
    $field->attribute == $request->field;
  });
} 

Thank you very much

kongulov commented 4 months ago

@fsavina-akqa Thank you very much for using the package.

Could you write what version of the packages you are using and post an example of use so that I can repeat the same problem myself and solve it

fsavina-akqa commented 4 months ago

Hi @kongulov, I'm using version 2.1.3.

Here is a simplified version of my Nova resource fields:

public function fields(NovaRequest $request)
{
    return [
        NovaTabTranslatable::make([
            Text::make('Title'),

            Slug::make('Slug')->from('title'),
        ]),

        Date::make('Date')->nullable(),

        NovaTabTranslatable::make([
            Text::make('Content')->nullable(),
        ]),
    ];
}

Just so you now, the structure of my resource is more complex and I'm using multiple NovaTabTranslatable instances for the sake of usability and content organisation.

Thanks again for your support, F.

fsavina-akqa commented 3 months ago

Hi @kongulov, any update on this topic?

Thanks, F.

fsavina commented 3 months ago

I've create a PR in order to fix this https://github.com/kongulov/nova-tab-translatable/pull/48

Thanks, F.

fsavina-akqa commented 3 months ago

Fixed in #48