Skip to content

Commit

Permalink
Merge pull request #98 from ahmedabdel3al/1.2
Browse files Browse the repository at this point in the history
Using allFields() method breaks export of relationship and computed fields
  • Loading branch information
patrickbrouwers authored Oct 8, 2020
2 parents 285cdff + 88a4001 commit cc91b4b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Actions/ExportToExcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function map($row): array
$row->setHidden([]);
$row = $this->replaceFieldValuesWhenOnResource(
$row,
is_array($only) ? $only : array_keys($row->attributesToArray())
$only
);
}

Expand Down
16 changes: 11 additions & 5 deletions src/Concerns/Only.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
trait Only
{
/**
* @var array|null
* @var array
*/
protected $only;
protected $only = [];

/**
* @var bool
Expand Down Expand Up @@ -50,7 +50,7 @@ public function allFields()
}

/**
* @return array|null
* @return array
*/
public function getOnly()
{
Expand All @@ -64,8 +64,14 @@ protected function handleOnly(ExportActionRequest $request)
{
// If not a specific only array, and user wants only index fields,
// fill the only with the index fields.
if ($this->onlyIndexFields && (!is_array($this->only) || count($this->only) === 0)) {
$this->only = $request->indexFields($request->newResource());
$indexFields = $request->indexFields($request->newResource());

if ($this->onlyIndexFields && count($this->only) === 0) {
$this->only = $indexFields;
} elseif (!$this->onlyIndexFields) {
$modelAttributes = optional($request->toQuery()->first())->attributesToArray() ?: [];

$this->only = array_merge(array_keys($modelAttributes), $indexFields);
}
}
}

1 comment on commit cc91b4b

@sairiz
Copy link

@sairiz sairiz commented on cc91b4b Oct 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

This commit breaks my application.

First it throws undefined index on all get mutator which return
$this->attributes['example']

Second, it throws trying to get property of non object on my hasOne relationship.
e.g $this->entity->name
Even if i change to $this->entity['name'] it still throws trying to access array offset on value of type null

Please sign in to comment.