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

Problem with slug preview #33

Closed VelziDM closed 1 year ago

VelziDM commented 1 year ago

Good afternoon. Thank you for the great package. But I have some issues, hope you can help. There is a 404 on preview for slug when you change the main field. This happens both when creating and updating. I think it's because the field name is changed from slug to translations_slug_en.

kongulov/nova-tab-translatable: 2.1.0 New version: 4.21.0 Laravel Framework 9.50.2 Php version: 8.1

 public function fields(NovaRequest $request): array
    {
        return [
            NovaTabTranslatable::make([
                                          Text::make('Title')
                                              ->rules('required')
                                              ->maxlength(255),
                                          Slug::make('Slug')->from('title'),
                                      ]),
        ];
    }

Thank you.

kongulov commented 1 year ago

@VelziDM

Thank you very much for finding the problem! Problem solved, please update the package to the new version (2.1.1)

VelziDM commented 1 year ago

Thanks a lot

rafaelsmith commented 1 year ago

@VelziDM

Thank you very much for finding the problem! Problem solved, please update the package to the new version (2.1.1)

Thanks for the updates! Unfortunately I get error after update when I type title: in_array(): Argument #2 ($haystack) must be of type array, null given {"userId":2,"exception":"[object] (TypeError(code: 0): in_array(): Argument #2 ($haystack) must be of type array, null given at vendor/kongulov/nova-tab-translatable/src/Http/Controllers/FieldPreviewController.php:32)

Nova version: 4.22.0

kongulov commented 1 year ago

@rafaelsmith

please send me NovaTabTranslatable::make([....]) so I can recreate the problem myself too. Is the problem only when updating the resource? Or and at creation too?

rafaelsmith commented 1 year ago

@rafaelsmith

please send me NovaTabTranslatable::make([....]) so I can recreate the problem myself too. Is the problem only when updating the resource? Or and at creation too?

It's only on create

            NovaTabTranslatable::make([
                Text::make('Title')->rules('required'),
                Slug::make('Slug')->from('Title')->separator('_')->hideFromIndex(),
                Textarea::make('Excerpt')
                    ->rules('required')
                    ->rows(2),
                Tiptap::make('Content')
                ->buttons(['heading','|','italic','bold','|','link','code','strike','underline','highlight','|','bulletList','orderedList','br','codeBlock','blockquote','|','horizontalRule','hardBreak','|','table','|','image','|','textAlign','|','rtl','|','history','|','editHtml'])
                ->headingLevels([2, 3, 4])
                ->imageSettings([
                    'disk' => 's3',
                    'path' => '/posts',
                ])
                ->rules('required'),
            ]),
kongulov commented 1 year ago

@rafaelsmith

You have a problem elsewhere. In the model, you must specify both keys as translatable public $translatable = ['title', 'slug'];

rafaelsmith commented 1 year ago

My bad... It was protected not public. Thanks for the update :)