The Td field is intended to modify the display of a table cell in the preview
mode.
make(Closure|string $label, ?Closure $fields = null)
make(Closure|string $label, ?Closure $fields = null)
make(Closure|string $label, ?Closure $fields = null)
make(Closure|string $label, ?Closure $fields = null)
make(Closure|string $label, ?Closure $fields = null)
$label
- column name
$fields
- a closure that returns an array of fields
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
]),
];
}
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
]),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
]),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
]),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
]),
];
}
//...
The Td field is not displayed in forms, it is intended only for preview
mode!
A closure can take the current element as a parameter.
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Decorations\Flex;
use MoonShine\Fields\Switcher;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
public function indexFields(): array
{
return [
Td::make('Column', function (Article $v) {
if($v->active) {
return [
Text::make('Title'),
];
}
return [
Flex::make([
ActionButton::make('Click me', $this->detailPageUrl($v)),
Text::make('Title'),
Switcher::make('Active'),
])
];
}),
];
}
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Decorations\Flex;
use MoonShine\Fields\Switcher;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', function (Article $v) {
if($v->active) {
return [
Text::make('Title'),
];
}
return [
Flex::make([
ActionButton::make('Click me', $this->detailPageUrl($v)),
Text::make('Title'),
Switcher::make('Active'),
])
];
}),
];
}
//...
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Decorations\Flex;
use MoonShine\Fields\Switcher;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', function (Article $v) {
if($v->active) {
return [
Text::make('Title'),
];
}
return [
Flex::make([
ActionButton::make('Click me', $this->detailPageUrl($v)),
Text::make('Title'),
Switcher::make('Active'),
])
];
}),
];
}
//...
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Decorations\Flex;
use MoonShine\Fields\Switcher;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', function (Article $v) {
if($v->active) {
return [
Text::make('Title'),
];
}
return [
Flex::make([
ActionButton::make('Click me', $this->detailPageUrl($v)),
Text::make('Title'),
Switcher::make('Active'),
])
];
}),
];
}
//...
use MoonShine\ActionButtons\ActionButton;
use MoonShine\Decorations\Flex;
use MoonShine\Fields\Switcher;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', function (Article $v) {
if($v->active) {
return [
Text::make('Title'),
];
}
return [
Flex::make([
ActionButton::make('Click me', $this->detailPageUrl($v)),
Text::make('Title'),
Switcher::make('Active'),
])
];
}),
];
}
//...
You can also specify which fields will be displayed in a cell using the fields()
method.
fields(Fields|Closure|array $fields)
fields(Fields|Closure|array $fields)
fields(Fields|Closure|array $fields)
fields(Fields|Closure|array $fields)
fields(Fields|Closure|array $fields)
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
]),
];
}
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
]),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
]),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
]),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
]),
];
}
//...
The withLabels()
method allows you to display a Label for fields in a cell.
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
])
->withLabels(),
];
}
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
])
->withLabels(),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
])
->withLabels(),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
])
->withLabels(),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column', fn () => [
Text::make('Title'),
])
->withLabels(),
];
}
//...
The Td field can be given additional attributes using the tdAttributes()
method.
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
])
->tdAttributes(fn (Article $data, ComponentAttributeBag $attr) => $data->getKey() === 2 ? $attr->merge([
'style' => 'background: lightgray'
]) : $attr),
];
}
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
])
->tdAttributes(fn (Article $data, ComponentAttributeBag $attr) => $data->getKey() === 2 ? $attr->merge([
'style' => 'background: lightgray'
]) : $attr),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
])
->tdAttributes(fn (Article $data, ComponentAttributeBag $attr) => $data->getKey() === 2 ? $attr->merge([
'style' => 'background: lightgray'
]) : $attr),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
])
->tdAttributes(fn (Article $data, ComponentAttributeBag $attr) => $data->getKey() === 2 ? $attr->merge([
'style' => 'background: lightgray'
]) : $attr),
];
}
//...
use MoonShine\Fields\Td;
use MoonShine\Fields\Text;
//...
public function indexFields(): array
{
return [
Td::make('Column')
->fields([
Text::make('Title')
])
->tdAttributes(fn (Article $data, ComponentAttributeBag $attr) => $data->getKey() === 2 ? $attr->merge([
'style' => 'background: lightgray'
]) : $attr),
];
}
//...