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.
External systems
Section titled “External systems”Configure the systems once:
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, optionallytarget(default_blank) andtrusted(defaultfalse). A column naming a system that is not configured throws anInvalidArgumentExceptionwhen it is rendered; checkisset(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 valueA/7?xcannot change the path). Paths are relative and contain only letters, digits,_ . / ~ -and{value}, no...httpsis required (httpoutside 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
targetof 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' => trueare opened withoutnoopener(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().
Links and the detail page
Section titled “Links and the detail page”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.