Related data invalidation

This is the official documentation of the forestadmin/laravel-forestadmin v2+ and forestadmin/symfony-forestadmin PHP agents.

Your actions may edit records that the user is currently viewing. This is usually not an issue, as after the successful execution of an action, Forest Admin will reload all data that is displayed on the current page.

This is always true, except for a single case: Related Data displayed in custom-built Summary Views ↗. In this case, to avoid displaying stale data, you may want to tell the GUI which data has gone stale.


In the example below, the “Add new transaction” action is accessible from the summary view. This action creates a new transaction and automatically refreshes the “Emitted transactions” Related Data section to see the new transaction.

use ForestAdmin\AgentPHP\DatasourceCustomizer\CollectionCustomizer;
use ForestAdmin\AgentPHP\DatasourceCustomizer\Decorators\Actions\BaseAction;
use ForestAdmin\AgentPHP\DatasourceCustomizer\Decorators\Actions\Context\ActionContextSingle;
use ForestAdmin\AgentPHP\DatasourceCustomizer\Decorators\Actions\ResultBuilder;
use ForestAdmin\AgentPHP\DatasourceCustomizer\Decorators\Actions\Types\ActionScope;

    function (CollectionCustomizer $builder) {
            'Add new transaction',
            new BaseAction(
                scope: ActionScope::SINGLE,
                execute: function(ActionContextSingle $context, ResultBuilder $resultBuilder) {
                    /* ... Create new transaction here ... */

                    // Tell the GUI to refresh the "emitted_transactions" related data section.
                    // (see left arrow of the screenshot above)
                    return $resultBuilder->success(
                        'New transaction emitted',
                        ['invalidated' => ['emitted_transactions']]

Last updated