diff --git a/README.md b/README.md index 7ba785c..0f17e72 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' => [ @@ -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 0186d39..3644e0f 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. @@ -25,7 +25,7 @@ public static 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 be685d5..1e7722c 100644 --- a/src/NovaChartjs.php +++ b/src/NovaChartjs.php @@ -62,11 +62,11 @@ 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, - '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')