Skip to content

Actions

Actions are buttons that do something with a record or a selection of records beyond create, edit and delete: approve a request, record an exit, hand over a document, open the record in another system.

use Anvil\Resource\Action;
public function actions(): array
{
return [
Action::make('approve')
->label('Approve')->icon('check2')->color('success')
->permission('orders.approve')
->visible(fn ($order) => $order->status === 'open')
->confirm('Approve the order?')
->inRow()
->handle(function ($order): string {
service('orders')->approve($order);
return 'The order has been approved.';
}),
];
}
Kind Defined in Shown Details
Record action Resource::actions() header of the detail and edit page; with inRow() in rows and cards Record actions
Action with a form ->form(...) on any action opens a dialog first Actions with a form
Link action ->link(...), ->url(...) opens a page, runs no code Links to pages
Bulk action Resource::bulkActions() toolbar of the list when records are selected Bulk actions
Relation action Relation::headerActions(), recordActions() in a related list on the detail page Relation actions
  1. The button sends a request to the component endpoint of the panel, with a token that names the resource and the record.
  2. The server loads the record through the resource (tenant, scopeQuery()); a record outside the scope answers 404.
  3. Permission (with policies) and visibility are checked again – a stale button cannot run an action that is no longer allowed (403).
  4. The input of the dialog is validated and converted (422 on errors).
  5. The handler runs in a database transaction and is written to the audit log as component.action. An exception rolls everything back.
  6. The user sees the returned message; the page or list is reloaded.

Details per step: Permissions and visibility, Record actions.

Place Which actions
Detail page header all visible and allowed record actions
Edit page header the same
Rows and cards of the list actions with inRow(), see In rows and cards
List toolbar with a selection bulk actions and delete
Related list on the detail page the relation’s header and record actions
API actions with a handler, if enabled