Closed 4unkur closed 5 years ago
This issue board is for tracking bugs, not general development questions. Please direct general questions to #nova on Laravel's Discord or #nova on the Larachat Slack Channel.
I reported a bug, this is not a question. withMeta
is not working with cards like it is described in the docs. Check https://nova.laravel.com/docs/1.0/customization/cards.html#card-options
There is a method which passes some data via withMeta
:
public function currentVisitors()
{
return $this->withMeta(['currentVisitors' => true]);
}
in the Card.vue
I was not able to get currentVisitors
, but was able to get it only when I passed it in NovaServiceProvider (described in the comment above)
I can't confirm, so I don't think this is a bug.
$ php artisan nova:card vendor/test-card
<?php
class TestCard extends Card
{
// (...)
public function currentVisitors()
{
return $this->withMeta(['currentVisitors' => 9943]);
}
}
public function cards(Request $request)
{
return [
(new TestCard)->currentVisitors(),
];
}
export default {
props: [
'card',
],
mounted() {
console.log(this.card.currentVisitors)
},
}
Should totally include the part in the docs, where you call the function when you instantiate the class. I got caught up on this for a while too.
seriously this important part
public function cards(Request $request)
{
return [
(new TestCard)->currentVisitors(),
];
}
never mention in documentation! i scratched my head for many days for this thing
I ended up setting the meta data in the constructor of my custom card as follows:
public function __construct()
{
parent::__construct();
$this->withMeta(['currentVisitors' => true]);
}
And i second (third ;)) that this should be added to the documentation.
is this the same for Tools? not much in the docs about inserting data here
I ended up setting the meta data in the constructor of my custom card as follows:
public function __construct() { parent::__construct(); $this->withMeta(['currentVisitors' => true]); }
And i second (third ;)) that this should be added to the documentation.
@riddla I don't think I can thank you enough for sharing this tip. I would have been lost trying to figure out how to pass this stuff for cards which are not associated with resources, ie User. Thank you!
The Nova documentation is open source, if you'd like to contribute :) https://github.com/laravel/nova-docs
In vue template I had to put card. in front of the meta keys then I was able to use it.
v-if="card.shouldShowSomething"
{{card.something}}
I was trying to pass some data to
Card.vue
like it was described in the docs: https://nova.laravel.com/docs/1.0/customization/cards.html#registering-cardsBut that didn't work, so I found a workaround:
I passed my data vie
withMeta
inNovaServiceProvider.php
and this did work. I'm not sure, maybe it's a bug in the docs?