nova-inline-relationship
nova-inline-relationship copied to clipboard
Use default Nova behaviour for index column for the fields
@YarinceP Would you mind giving us some context around exactly what you are wanting? Thanks!
@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
@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;
}