Replies: 2 comments
-
|
For anyone else encountering this, I found a more reliable workaround for my particular use case, which is attaching statuses to various resources via those resources' detail pages: public function fields(NovaRequest $request)
{
return [
MorphTo::make('Statusable')->types([
Listing::class,
Order::class,
]),
Select::make('Status')
->dependsOn(
'statusable',
function (Select $field, NovaRequest $request, FormData $formData)
{
$resourceKey = $request->viaResource;
$resourceId = $request->viaResourceId; // In case you need it for something...I did
$resourceCls = Laravel\Nova\Nova::resourceForKey($resourceKey);
logger()->debug($resourceCls::$model);
return $field;
}
),
];
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
You can use the following: return [
- MorphTo::make('Statusable')->types([
+ $statusable = MorphTo::make('Statusable')->types([
Listing::class,
Order::class,
]),
Select::make('Status')
->dependsOn(
- 'statusable',
+ $statusable,
function (Select $field, NovaRequest $request, FormData $formData)
{
- logger()->debug($formData->statusable);
+ logger()->debug($formData->statusable_type);
return $field;
}
),
]; |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Description:
When using
->dependsOnwith aMorphTofield, theMorphToattribute inFormDatadoesn't allow me to access the polymorphic relation's class – only its ID. This was reported in #4518, and marked as fixed, but I'm still running into this problem now.Detailed steps to reproduce the issue on a fresh Nova installation:
With this
fieldsmethod on aStatusresource:The only thing that will be logged by the
logger()->debug($formData->statusable)line is a model ID, so it's impossible to retrieve the polymorphic relationship by the$formDatainformation alone.I've hacked around this by accessing the static
$modelattribute onMorphTo::morphToResourceas shown below, but this definitely doesn't feel like the right way to it:Thanks! Let me know if more info is needed.
Beta Was this translation helpful? Give feedback.
All reactions