kirschbaum-development / nova-inline-relationship

A package to present relationships as inline properties in Nova.
MIT License
196 stars 84 forks source link

Undefined Index: value #91

Open alekmlynek opened 3 years ago

alekmlynek commented 3 years ago

When using this with a one-to-one relationship, Nova throws an error "Undefined index: value".

Full error: Undefined index: values {"userId":2,"exception":"[object] (ErrorException(code: 0): Undefined index: values at /var/www/vendor/kirschbaum-development/nova-inline-relationship/src/NovaInlineRelationship.php:520)

public function fields(Request $request)
     {
       return [
         ID::make(__('ID'), 'id')->sortable(),
         HasOne::make('Delivery Options', 'deliveryOption', ShippingZoneDeliveryOption::class)->inline(),

If I take out "inline" the relationship works. I can create, update and do all the regular things. As a matter of fact, if I create the relationship traditionally and then enable inline on it, I can update it normally.

The issue seems to be with creating it. I'm using the latest Nova/Laravel version.

-- Edit -- When I trace the code NovaInlineRelationship.php:520, it seems like $itemData only has a 'modelId' property, but no values, so an error is being thrown.

▾ $itemData = (array [1])
|    ⬦ $itemData["modelId"] = (string [1]) `0`
alekmlynek commented 3 years ago

Ok, I resolved the issue. I was using a "heading" field, which has no form value (It is a label). This module does not support this, and throws the error.

Unsure the best way to fix this. Potentially guarding if values are set before trying to use them, essentially omitting fields that don't need to be processed.

I don't see this as an urgent issue. Current work-around is not to use helper fields like markup/heading. Fix would be nice to keep large inline relationships user friendly.