4

I'm creating a Tool for Laravel Nova 2.0

In my Tool I want to send a list of stuff to the Vue component:

in the PHP src for my tool I have a function that generates the "meta", as suggested in the documentation here:

public function stuff() {

    $stuff = [];

    ... 

    return $this->withMeta(['stuff' => $stuff]);
}

In my NovaServiceProvider.php I instantiate the tool and call the meta function. i.e.

public function tools()
{
    return [
        (new Tool())->stuff(),
    ];
}

However, nothing is passed to the Tool.vue component, (I have spent sometime inspecting it!) i.e.:

mounted() {
    console.log(this.stuff); // undefined 
},

Issue is discussed here: https://github.com/laravel/nova-issues/issues/761, however note that I am using a Tool and not a ResourceTool, or a Card.

Is this a bug with Tools, or something I'm doing wrong? Is there a workaround?

benedict_w
  • 3,543
  • 1
  • 32
  • 49

1 Answers1

1

I haven't tried creating a custom tool yet, but for the custom field you can get the metadata using:

mounted() {
    console.log(this.field.stuff);
},

if you're having troubles with similar stuff, i suggest printing the content of the class in the console in a json format, it makes it easier for you to troubleshoot the problem

mounted() {
    console.log(JSON.stringify(this));
},

Although i don't think this is the problem can you try modifying your stuff() function to:

public function stuff()
{
    $stuff = [];
    $this->withMeta(['stuff' => $stuff]);
    return $this;
}
Hadi Najem
  • 338
  • 4
  • 12