Skip to content

Commit

Permalink
Improve flow for resolveIndexAttributes (#532)
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkirkosa authored Jan 20, 2023
1 parent f62d60f commit 9aa97d6
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/Repositories/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,28 +436,11 @@ public function resolveShowAttributes(RestifyRequest $request)
*/
public function resolveIndexAttributes($request)
{
// Resolve the show method, and attach the value to the array
$fields = $this
->collectFields($request)
->when($this->hasCustomColumns(), fn (FieldCollection $fields) => $fields->inList($this->getColumns()))
->forIndex($request, $this)
->filter(fn (Field $field) => $field->authorize($request))
->when(
$this->eagerState,
function ($items) {
return $items->filter(fn (Field $field) => ! $field instanceof EagerField);
}
)
->each(fn (Field $field) => $field->resolveForIndex($this))
->map(fn (Field $field) => $field->serializeToValue($request))
->mapWithKeys(fn ($value) => $value)
->all();

if ($this instanceof Mergeable) {
// Hidden and authorized index fields
$fields = $this->modelAttributes($request)
return $this->modelAttributes($request)
->filter(function ($value, $attribute) use ($request) {
/** * @var Field $field */
/** @var Field $field */
$field = $this->collectFields($request)->firstWhere('attribute', $attribute);

if (is_null($field)) {
Expand All @@ -476,7 +459,23 @@ function ($items) {
})->all();
}

return $fields;
// Resolve the show method, and attach the value to the array
return $this
->collectFields($request)
->when(
$this->hasCustomColumns(),
fn (FieldCollection $fields) => $fields->inList($this->getColumns())
)
->forIndex($request, $this)
->filter(fn (Field $field) => $field->authorize($request))
->when(
$this->eagerState,
fn ($items) => $items->filter(fn (Field $field) => ! $field instanceof EagerField)
)
->each(fn (Field $field) => $field->resolveForIndex($this))
->map(fn (Field $field) => $field->serializeToValue($request))
->mapWithKeys(fn ($value) => $value)
->all();
}

public function resolveShowMeta($request)
Expand Down

0 comments on commit 9aa97d6

Please sign in to comment.