From 997d60d9e9906f38cbc55c152d46f8c57d5f6d1a Mon Sep 17 00:00:00 2001 From: Krot Eval <38257723+4n70w4@users.noreply.github.com> Date: Wed, 13 Jan 2021 19:28:07 +0300 Subject: [PATCH 1/2] unstatic getNovaChartjsSettings --- README.md | 6 +++--- src/Contracts/Chartable.php | 2 +- src/NovaChartjs.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7ba785c..7e9f428 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ php artisan migrate After setup, your model should include the `KirschbaumDevelopment\NovaChartjs\Traits\HasChart` trait and you must implement the `KirschbaumDevelopment\NovaChartjs\Contracts\Chartable` Contract. -You must also define a static `getNovaChartjsSettings` function in the model which should return the required settings for the Chart. All other required methods and relationship defined in the contract are already defined for you in the included trait. You can also override these trait methods directly on your model. +You must also define a `getNovaChartjsSettings` function in the model which should return the required settings for the Chart. All other required methods and relationship defined in the contract are already defined for you in the included trait. You can also override these trait methods directly on your model. ```php use KirschbaumDevelopment\NovaChartjs\Traits\HasChart; @@ -48,7 +48,7 @@ class Employee extends Model implements Chartable * * @return array */ - public static function getNovaChartjsSettings(): array + public function getNovaChartjsSettings(): array { return [ 'default' => [ @@ -277,7 +277,7 @@ class Employee extends Model implements Chartable * * @return array */ - public static function getNovaChartjsSettings(): array + public function getNovaChartjsSettings(): array { return [ 'default' => [ diff --git a/src/Contracts/Chartable.php b/src/Contracts/Chartable.php index 0186d39..56b9654 100644 --- a/src/Contracts/Chartable.php +++ b/src/Contracts/Chartable.php @@ -16,7 +16,7 @@ public function novaChartjsMetricValue(): MorphMany; * * @return array */ - public static function getNovaChartjsSettings(): array; + public function getNovaChartjsSettings(): array; /** * Return a list of all models available for comparison to root model. diff --git a/src/NovaChartjs.php b/src/NovaChartjs.php index be685d5..8fa5c32 100644 --- a/src/NovaChartjs.php +++ b/src/NovaChartjs.php @@ -62,7 +62,7 @@ public function resolve($resource, $attribute = null) } if (! empty($resource)) { - $settings = data_get($resource::getNovaChartjsSettings(), $this->getChartName(), []); + $settings = data_get($resource->getNovaChartjsSettings(), $this->getChartName(), []); $this->withMeta([ 'settings' => $settings, From 14cf91d67b3b25c8e69b17d97314daae68ff4052 Mon Sep 17 00:00:00 2001 From: Krot Eval <38257723+4n70w4@users.noreply.github.com> Date: Wed, 13 Jan 2021 19:49:59 +0300 Subject: [PATCH 2/2] unstaic getNovaChartjsComparisonData --- README.md | 4 ++-- src/Contracts/Chartable.php | 2 +- src/NovaChartjs.php | 2 +- src/Traits/HasChart.php | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 7e9f428..0f17e72 100644 --- a/README.md +++ b/README.md @@ -340,7 +340,7 @@ You can add or remove any model to comparison to checkout how models are stacked ## Changing Comparison Data -Chart comparison data is fetched through trait using a static function `getNovaChartjsComparisonData`. You can override this function in your model to change the comparison data. +Chart comparison data is fetched through trait using a function `getNovaChartjsComparisonData`. You can override this function in your model to change the comparison data. ```php namespace App; @@ -359,7 +359,7 @@ class Employee extends Model implements Chartable * * @return \Illuminate\Database\Eloquent\Collection */ - public static function getNovaChartjsComparisonData(): array + public function getNovaChartjsComparisonData(): array { return static::with('novaChartjsMetricValue') ->has('novaChartjsMetricValue') diff --git a/src/Contracts/Chartable.php b/src/Contracts/Chartable.php index 56b9654..3644e0f 100644 --- a/src/Contracts/Chartable.php +++ b/src/Contracts/Chartable.php @@ -25,7 +25,7 @@ public function getNovaChartjsSettings(): array; * * @return array */ - public static function getNovaChartjsComparisonData($chartName = 'default'): array; + public function getNovaChartjsComparisonData($chartName = 'default'): array; /** * Return a list of additional datasets added to chart. diff --git a/src/NovaChartjs.php b/src/NovaChartjs.php index 8fa5c32..1e7722c 100644 --- a/src/NovaChartjs.php +++ b/src/NovaChartjs.php @@ -66,7 +66,7 @@ public function resolve($resource, $attribute = null) $this->withMeta([ 'settings' => $settings, - 'comparison' => $resource::getNovaChartjsComparisonData($this->getChartName()), + 'comparison' => $resource->getNovaChartjsComparisonData($this->getChartName()), 'additionalDatasets' => data_get($resource->getAdditionalDatasets(), $this->getChartName(), []), 'model' => Str::singular(Str::title(Str::snake(class_basename($resource), ' '))), 'title' => $this->getChartableProp($resource, $settings['titleProp'] ?? $resource->getKeyName()), diff --git a/src/Traits/HasChart.php b/src/Traits/HasChart.php index 2e6698c..dc606ee 100644 --- a/src/Traits/HasChart.php +++ b/src/Traits/HasChart.php @@ -75,7 +75,7 @@ public function setNovaChartjsMetricValueAttribute($value): void * * @return array */ - public static function getNovaChartjsComparisonData($chartName = 'default'): array + public function getNovaChartjsComparisonData($chartName = 'default'): array { return static::with('novaChartjsMetricValue') ->has('novaChartjsMetricValue')