Skip to content

Commit

Permalink
Make excludeAttributesFromImport static
Browse files Browse the repository at this point in the history
  • Loading branch information
simonhamp authored Dec 14, 2020
1 parent 50d07b8 commit 29324a8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 3 additions & 2 deletions src/Http/Controllers/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
}

Expand Down

0 comments on commit 29324a8

Please sign in to comment.