Add fields
How does it work?
Field
Description
Examples
Adding a field by concatenating other fields
use ForestAdmin\AgentPHP\DatasourceCustomizer\CollectionCustomizer;
use ForestAdmin\AgentPHP\DatasourceCustomizer\Decorators\Computed\ComputedDefinition;
use ForestAdmin\AgentPHP\DatasourceToolkit\Components\Query\ConditionTree\Operators;
// "User" Collection has the following structure: { id, firstName, lastName }
$forestAgent->customizeCollection(
'User',
function (CollectionCustomizer $builder) {
$builder->addField(
'displayName',
new ComputedDefinition(
// Type of the new field
columnType: 'String',
// Dependencies which are needed to compute the new field (must not be empty)
dependencies: ['firstName', 'lastName'],
// Compute function for the new field
// Note that the function computes the new values in batches: the return value must be
// an array which contains the new values in the same order than the provided records.
values: fn ($records) => collect($records)->map(fn ($record) => $record['firstName'] . ' ' . $record['lastName']),
)
);
}
);Adding a field that depends on another computed field
Adding a field that depends on a many-to-one relationship
Adding a field that depends on a one-to-many relationship
Adding a field fetching data from an API
Performance
Last updated