Laravel Nova - Reload index view of a resource

Viewed 2635

I'm developing my first Nova field. It's an index field that contains a button which sends an Axios request, and when a response is being returned I need to reload the index view.

For now I got this:

this.$router.go(this.$router.currentRoute);

The problem is that it refreshes the entire page (a hard-refresh, like when you press Cmd+R). I just want to reload the current route (which is the index route of a resource).

I also tried this:

            this.$router.push({
                name: 'index',
                params: {
                    resourceName: this.resourceName,
                },
            });

But since I pushed the same route, it does nothing.

Any ideas?

Thank's, Daniel.

1 Answers

You can try something like this

let currentFilters = _.cloneDeep(this.$store.state[`${this.resourceName}`]['filters']);
await this.$store.commit(`${this.resourceName}/storeFilters`, {});
await this.$store.commit(`${this.resourceName}/storeFilters`, currentFilters);

This code will reset currently applied filters to empty object and then requests old filters again which leads to resource index updating. But be careful - this method makes two requests to the server.

I'm facing the same issue now while trying to implement custom popup component - but that's all I could do with implemented in Nova vuex store.

Idea of implementation was taken from https://github.com/tanmuhittin/nova-reload-resources/blob/f27da9507a97696b7aca0e9bd7e5afd3001f0891/resources/js/components/Card.vue#L21

Related