ListField
Displays a list of links or strings. This is purely for the purposes of displaying data such as relationships on the edit page - the data here cannot be updated.
To use, set a getter function. This will be passed the model that is being edited and should return an array of items to list.
Links
To display a list of links, the items in the array should include a url and name parameter.
ListField::make('things')
->setDataGetter(function ($item) {
return $item->things->map(function ($thing) {
return [
'name' => $thing->title,
'url' => route('admin.users.edit', $thing->getKey()),
];
});
}),
Plain Text
To display a plain text list, just provide an id attribute.
ListField::make('things')
->setDataGetter(function ($item) {
return $item->things->map(function ($thing) {
return [
'id' => $thing->getKey(),
];
});
}),
Attributes
In addition to the name, url and id array values, you may also pass an attributes array to either type of list. These attributes will be applied directly to the corresponding <a> or <div> tag directly inside the <li>.
ListField::make('things')
->setDataGetter(function ($item) {
return $item->things->map(function ($thing) use ($item) {
return [
'name' => $thing->title,
'url' => route('admin.users.edit', $thing->getKey()),
'attributes' => [
'target' => '_blank',
'class' => $item->is($thing) ? 'current' : '',
],
];
});
}),
NOTE: If you provide a target="_blank" attribute, the list field will automatically apply rel="noopener noreferrer". Providing your own will override this functionality.