Blueq-world / laravel-nova-inlineIndex

Inline update resource field, support text and number update
6 stars 4 forks source link

Refresh resource on save? #2

Closed babul closed 2 months ago

babul commented 3 years ago

This package works well allowing for my use case of editing a field on the index view. But I have a calculated field based on the edited value, which does not get refreshed automatically. A manual browser refresh does show the updated calculated field.

Is there a way to refresh the row/resource after an edit?

manyasone commented 3 years ago

In this package's IndexField.vue there's this computed property:

    shouldRefresh() {
      return this.field.refreshOnSaving;
    },

So out of the box you can use this in meta.

To simplify the handling, I've extended the field's php class with this method:

    /**
     *
     * @param  mixed  $refreshOnSaving
     * @return $this
     */
    public function refreshOnSaving($refreshOnSaving = true)
    {
        return $this->withMeta(['refreshOnSaving' => $refreshOnSaving]);
    }`

Now i can use it like this:

InlineIndex::make(__('validation.attributes.stock_count'), 'stock_count')
    ->refreshOnSaving()

Note: This refreshes the entire table, not just a single row. So it could be a little smoother if your could also just update one row. However I don't think you can do this without overwriting the nova core (ResourceTableRow)