Skip to content

MorphTo in ->dependsOn() not returning model type, only id #4518

@cverster

Description

@cverster
  • Laravel Version: 9.11
  • Nova Version: 4.11
  • PHP Version: 8.1.6
  • Database Driver & Version: mysql 8.0.29
  • Operating System and Version: Linux Ubuntu 5.4.0-121-generic
  • Browser type and version: Chrome
  • Reproduction Repository: N/A

Description:

I have a Nova resource with the following in the fields method:

    public function fields(NovaRequest $request)
    {
        return [
            ID::make()->sortable()
                ->hideFromIndex(),

            BelongsTo::make('Alert'),

            MorphTo::make('Recipient', 'messageable')
                ->types([
                    User::class,
                    TelegramGroup::class,
                ]),

            Select::make('Type')
                ->dependsOn(
                    ['messageable'],
                    function (Select $field, NovaRequest $request, FormData $formData) {
                        if ($formData->messageable instanceof \App\Models\User) {
                            $field->options([
                                'telegram' => 'Telegram',
                                'email' => 'Email',
                                'sms' => 'SMS',
                            ]);
                        } elseif ($formData->messageable instanceof \App\Models\TelegramGroup) {
                            $field->options([
                                'telegram' => 'Telegram',
                            ]);
                        }
                    }
                ),
        ];
    }

This is currently not working, as the $formData->messageable just returns a string (with the value of the id of the model being called).
As seen below, it's also the only thing that is contained in the messageable field.

image

Should this not return the model type of the Polymorphic relationship model also?

Metadata

Metadata

Assignees

Labels

bugVerified bug by the Nova team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions