Skip to content

Links

Columns link to the detail page of a referenced record (linkToRecord()) or to pages of external systems configured in Config\Anvil::$links. Arbitrary URLs cannot be linked – a value from the database can never become a javascript: link or point to a foreign site.

Configure the systems once:

app/Config/Anvil.php
public array $links = [
'hr' => ['url' => 'https://hr.example.com/person/', 'target' => 'hr', 'trusted' => true],
'contracts' => 'https://contracts.example.com/',
];

and link columns to them:

TextColumn::make('personnel_number')->link('hr'), // …/person/<value>
TextColumn::make('contract_number')->link('contracts', 'contracts/{value}'),
TextColumn::make('name')->link('contracts', 'by-owner/{value}', value: fn ($row) => $row->owner_id),
TextColumn::make('ticket')->link('helpdesk', 'tickets/{value}', target: Link::SAME),

link(system, path = '{value}', value: null, target: null):

Argument Meaning
system key in $links
path path appended to the URL of the system; {value} is replaced by the encoded value
value closure that returns the value for the link instead of the column value
target Link::SAME (_self), Link::NEW (_blank) or a tab name such as 'hr'
  • Systems: a string is the URL; an array has url, optionally target (default _blank) and trusted (default false). A column naming a system that is not configured throws an InvalidArgumentException when it is rendered; check isset(Config\Anvil::resolve()->links['hr']) if a system is optional.
  • Address: the URL of the system plus the path; {value} is replaced by the encoded value (a value A/7?x cannot change the path). Paths are relative and contain only letters, digits, _ . / ~ - and {value}, no ... https is required (http outside production).
  • Value: the column value, or the result of value:; without a value (null or empty) the column shows plain text.
  • Target: per link, else the target of the system, else a new tab.
  • Opener: external pages are opened with rel="noopener noreferrer": they cannot reach or redirect the Anvil window. Browsers then cannot find a named tab again, so every click opens a new one. Systems marked 'trusted' => true are opened without noopener (still without referrer) and reuse their named tab; mark only systems of your own organisation, because their pages could redirect the Anvil tab.
  • External links get a small arrow icon after the value.
  • A link only opens the page: what the user may see there is decided by the other system.

Actions open the same kind of links with Action::link() and pages of the application with Action::url().

The first column of a row links to the detail page of the record when the user may view it – unless that column has a link of its own. Put the external link on another column if the first one should open the record.