From a24609d7757d6a2436203ccdf4dc9ae23424a691 Mon Sep 17 00:00:00 2001 From: Alan Vb Date: Tue, 17 Aug 2021 18:39:33 +0300 Subject: [PATCH] Implemented usage of model attributes first --- CHANGELOG.md | 3 +++ src/NovaExportAction.php | 16 +++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d37985..b3a2fea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ All notable changes in Laravel Nova Exports will be documented in this file +## 1.1.2 +- Implemented usage of model attributes first + ## 1.1.1 - Added `disk()` method for external storages. diff --git a/src/NovaExportAction.php b/src/NovaExportAction.php index 912f93d..d6da898 100644 --- a/src/NovaExportAction.php +++ b/src/NovaExportAction.php @@ -88,11 +88,17 @@ public function __construct(NovaResource $novaResource) $this->table = $this->model->getTable(); - $this->tableColumns = collect( - Schema::getColumnListing( - $this->table - ) - ); + $modelAttributes = array_keys($novaResource->resource->getAttributes()); + + if (!blank($modelAttributes)) { + $this->tableColumns = collect($modelAttributes); + } else { + $this->tableColumns = collect( + Schema::getColumnListing( + $this->table + ) + ); + } $this->queryBuilder = DB::table( $this->table