# Actions

{% hint style="success" %}
This is the official documentation of the `forestadmin/laravel-forestadmin` v2+ and `forestadmin/symfony-forestadmin` PHP agents.
{% endhint %}

Sooner or later, you will need to perform actions on your data that are specific to your business.

Moderating comments, generating invoices, logging into a customer’s account, or banning users are exactly the kind of important tasks to unlock to manage your day-to-day operations.

![Custom Action displayed in a Table View](https://647272774-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FABtuALf2WDQ7fxhI0JPa%2Fuploads%2Fgit-blob-d43582d7cd00503688418f24ec3689808dc40730%2Factions-dropdown.png?alt=media)

### In your code

To create an Action, you will first need to declare it in your code for a specific collection. Here we declare a "Mark as Live" Action for the `companies` collection.

The action behavior is implemented in the `execute` parameter of BaseAction.

```php
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\Types\ActionScope;

$forestAgent->customizeCollection(
    'companies',
    function (CollectionCustomizer $builder) {
        $builder->addAction(
            'Mark as Live',
            new BaseAction(
                scope: ActionScope::GLOBAL,
                execute: function (ActionContextSingle $context) {
                    // Implement your controller here.
                }
            )
        );
    }
);
```

| Property          | Usage       | Description                                                                                                                                                                                                                                                                                                                                                                      |
| ----------------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| scope             | **require** | `Single`, `Global` or `Bulk`. See [here](https://docs.forestadmin.com/developer-guide-agents-php/agent-customization/actions/scope-context) for more detail                                                                                                                                                                                                                      |
| execute           | **require** | The callable called when the action is executed, with `context` and `result builder` as parameters. See [context](https://docs.forestadmin.com/developer-guide-agents-php/agent-customization/scope-context#the-context-object) and [result builder](https://docs.forestadmin.com/developer-guide-agents-php/agent-customization/actions/result-builder) pages for more details. |
| form              | *optional*  | A list of static fields to be input by the user or a function called with `context` as parameters which returns a list of fields. See [form](https://docs.forestadmin.com/developer-guide-agents-php/agent-customization/actions/forms-dynamic) page for more details.                                                                                                           |
| description       | *optional*  | An optional description of the action. *Default: null*                                                                                                                                                                                                                                                                                                                           |
| submitButtonLabel | *optional*  | A custom label for the submit button. *Default: the action name*                                                                                                                                                                                                                                                                                                                 |

### In the admin panel

After declaring it, the Action will appear in the Smart Actions tab within your Collection Settings.

{% hint style="info" %}
An Action is displayed in the UI only if:

* it is set as "visible" (see screenshot below) AND
* in non-development environments, the user's role must grant the "trigger" permission
  {% endhint %}

You must make the Action visible there if you wish users to be able to see it in this Team.

![Making the Action visible](https://647272774-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FABtuALf2WDQ7fxhI0JPa%2Fuploads%2Fgit-blob-a2c3d4ee72768a9fa63d091617829bbf9b026488%2Factions-visibility.png?alt=media)
