kirschbaum-development / nova-inline-relationship

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

Use default Nova behaviour for index column for the fields #53

Open YarinceP opened 4 years ago

brandonferens commented 4 years ago

@YarinceP Would you mind giving us some context around exactly what you are wanting? Thanks!

genesiscz commented 4 years ago

@brandonferens Why does BelongsTo (which is just MANY to one or ONE to one show up at index like "1 address" instead of that address? i guess that's what OP meant

genesiscz commented 4 years ago

@YarinceP

Could you look up into this or is this project simply dead?

It's not so hard to fix this. I've been able to do these changes to make this half-work (without the link tho)

IndexField.vue

        indexLabel: function() {
            if (this.field.value instanceof String || typeof this.field.value == "string") {
                return this.field.value;
            }
            let count = Object.keys(this.field.value).length;
            let label = (count > 1) ? this.field.pluralLabel : this.field.singularLabel;
            return count == 1 ? `${this.field.value}` : `${count} ${label}`;
        }
    }

NovaInlineRelationship.php, function updateFieldValue, before the last $this->value = ...


        // Ajax request for ïndex page
        if (strpos($request->fullUrl(), "search=") !== false && $this->isSingularRelationship($resource, $attribute)) {
            if (! $resource instanceof \Laravel\Nova\Resource) {
                $this->value = Nova::newResourceFromModel($resource)->title();
            } else {
                $this->value = $resource->title();
            }
            return;
        }