From 29324a82702258b1173f6893b4153f24ed24de8f Mon Sep 17 00:00:00 2001 From: Simon Hamp Date: Mon, 14 Dec 2020 19:35:50 +0000 Subject: [PATCH] Make excludeAttributesFromImport static --- README.md | 2 +- src/Http/Controllers/ImportController.php | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 30dcd31..7f5776b 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ Add this static property to your Resource to prevent it from showing up in the N `public static function canImportResource($request): bool` Define a `canImportResource` method to use more complex logic to decide if this Resource can be shown during import. If defined, this takes precedence over the `$canImportResource` property. -`public function excludeAttributesFromImport(): array` +`public static function excludeAttributesFromImport(): array` *Default:* `[]` Define a `excludeAttributesFromImport` method that returns an array of attribute names that you want to _exclude_ from being visible in the import tool for this Resource. diff --git a/src/Http/Controllers/ImportController.php b/src/Http/Controllers/ImportController.php index b3d1ca1..bd4d619 100644 --- a/src/Http/Controllers/ImportController.php +++ b/src/Http/Controllers/ImportController.php @@ -54,8 +54,9 @@ public function getAvailableFieldsForImport(String $resource, $request) $novaResource = new $resource(new $resource::$model); $fieldsCollection = collect($novaResource->creationFields($request)); - if (method_exists($novaResource, 'excludeAttributesFromImport')) {$fieldsCollection = $fieldsCollection->filter(function(Field $field) use ($novaResource, $request) { - return !in_array($field->attribute, $novaResource->excludeAttributesFromImport($request)); + if (method_exists($novaResource, 'excludeAttributesFromImport')) { + $fieldsCollection = $fieldsCollection->filter(function(Field $field) use ($novaResource, $request) { + return !in_array($field->attribute, $novaResource::excludeAttributesFromImport($request)); }); }