Skip to content

Commit

Permalink
Determine fields based on results of query callback if one is present
Browse files Browse the repository at this point in the history
  • Loading branch information
DivineOmega committed Mar 25, 2021
1 parent 765657d commit 5106acf
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Objects/Sources/EloquentSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ public function __construct($eloquentModelClassName, $queryCallback = null)
$this->model = new $eloquentModelClassName();
$this->queryCallback = $queryCallback;

$this->fields = array_keys($this->model->first()->getAttributes());
$query = $this->model->query();

if (is_callable($this->queryCallback)) {
$queryCallback = $this->queryCallback;
$queryCallback($query);
}

$this->fields = array_keys($query->first()->getAttributes());
}

public function getDataRows(int $page = 1, array $fieldsToRetrieve = []): array
Expand Down

0 comments on commit 5106acf

Please sign in to comment.