Skip to content

Commit

Permalink
New admin.list.extendRecords event (#989)
Browse files Browse the repository at this point in the history
  • Loading branch information
thienvu18 authored Jun 11, 2022
1 parent f70ccc7 commit aeb055b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/admin/actions/ListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ public function makeList($alias)
$this->controller->listExtendQuery($query, $alias);
});

$widget->bindEvent('list.extendRecords', function ($records) use ($alias) {
return $this->controller->listExtendRecords($records, $alias);
});

$widget->bindEvent('list.overrideColumnValue', function ($record, $column, $value) use ($alias) {
return $this->controller->listOverrideColumnValue($record, $column, $alias);
});
Expand Down
9 changes: 9 additions & 0 deletions app/admin/traits/ListExtendable.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public function listExtendQuery($query, $alias = null)
{
}

/**
* listExtendRecords controller override: Extend the records used for populating the list
* after the query is processed.
* @param Illuminate\Contracts\Pagination\LengthAwarePaginator|Illuminate\Database\Eloquent\Collection $records
*/
public function listExtendRecords($records, $alias = null)
{
}

/**
* Controller override: Extend the query used for populating the filter
* options before the default query is processed.
Expand Down
4 changes: 4 additions & 0 deletions app/admin/widgets/Lists.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,10 @@ protected function getRecords()
$records = $model->get();
}

if ($event = $this->fireSystemEvent('admin.list.extendRecords', [&$records])) {
$records = $event;
}

return $this->records = $records;
}

Expand Down

0 comments on commit aeb055b

Please sign in to comment.