Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Polymorphic Relationships #440

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Sauruz
Copy link

@Sauruz Sauruz commented Feb 16, 2023

In polymorphic relationships the nested content is not decoded/casted to an array.

This fix will test again if the nested json object can be decoded to an array and will set the keys correct.

See: #435

Screenshot 2023-02-16 at 10 04 53

@toonvandenbos
Copy link
Member

Hi @Sauruz, can you give some more details about the exact workflow inside Nova triggering this issue? In #435 you're talking about MorphOne, could you add screenshots or a concrete example? Thanks.

@Keko-94
Copy link

Keko-94 commented Apr 20, 2023

@Sauruz Thank you for the fix but the validations doesn't work properly.
Try to add required in your meta_title and check if it passes.

@toonvandenbos you can reproduce the bug like this:
MorphOne::make('Quiz', 'qcm', Qcm::class)

Nova\Qcm.php

public function fields(NovaRequest $request): array
    {
        return [
            Text::make(__('Label'), 'label')
                ->filterable()
                ->sortable()
                ->rules('required'),

            Textarea::make(__('Description'), 'description'),

            Flexible::make('Questions', 'questions')
                ->button(trans_choice(__('Add a new :resource'), 1, ['resource' => 'question']))
                ->addLayout(QuestionLayout::class)
                ->resolver(QuestionResolver::class)
                ->confirmRemove(trans_choice(__('Are you sure you want to delete this :resource ?'), 1, ['resource' => 'question']), __('Yes'), __('No'))
                ->rules('required')
                ->limit(10)
                ->fullWidth()
                ->collapsed(true)
        ];
    }

Nova\Flexible\Layouts\QuestionLayout.php

public function fields(): array
    {
        return [
            Text::make('Question', 'label')
                ->rules('required'),

            Textarea::make(__('Explanation'), 'explanation')
                ->rows(3),

            Flexible::make(__('Answers'), 'answer--nested-flexible')
                ->button(trans_choice(__('Add a new :resource'), 1, ['resource' => strtolower(__('Answer'))]))
                ->addLayout(AnswerLayout::class)
                ->resolver(AnswerResolver::class)
                ->confirmRemove(trans_choice(__('Are you sure you want to delete this :resource ?'), 1, ['resource' => strtolower(__('Answer'))]), __('Yes'), __('No'))
                ->rules('required', new MinFlexibleLayoutsRule(2))
                ->limit(10)
                ->fullWidth()
                ->collapsed(true)
        ];
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants