[增添]添加了datasource的setting数据库以及默认值

This commit is contained in:
makotocc0107
2024-08-27 09:57:44 +08:00
parent d111dfaea4
commit 72eb990970
10955 changed files with 978898 additions and 0 deletions

View File

@@ -0,0 +1,641 @@
---
title: Getting started
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
import LaracastsBanner from "@components/LaracastsBanner.astro"
## Overview
<LaracastsBanner
title="Table Columns"
description="Watch the Rapid Laravel Development with Filament series on Laracasts - it will teach you the basics of adding columns to Filament resource tables."
url="https://laracasts.com/series/rapid-laravel-development-with-filament/episodes/9"
series="rapid-laravel-development"
/>
Column classes can be found in the `Filament\Tables\Columns` namespace. You can put them inside the `$table->columns()` method:
```php
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->columns([
// ...
]);
}
```
Columns may be created using the static `make()` method, passing its unique name. The name of the column should correspond to a column or accessor on your model. You may use "dot notation" to access columns within relationships.
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
TextColumn::make('author.name')
```
## Available columns
Filament ships with two main types of columns - static and editable.
Static columns display data to the user:
- [Text column](text)
- [Icon column](icon)
- [Image column](image)
- [Color column](color)
Editable columns allow the user to update data in the database without leaving the table:
- [Select column](select)
- [Toggle column](toggle)
- [Text input column](text-input)
- [Checkbox column](checkbox)
You may also [create your own custom columns](custom) to display data however you wish.
## Setting a label
By default, the label of the column, which is displayed in the header of the table, is generated from the name of the column. You may customize this using the `label()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->label('Post title')
```
Optionally, you can have the label automatically translated [using Laravel's localization features](https://laravel.com/docs/localization) with the `translateLabel()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->translateLabel() // Equivalent to `label(__('Title'))`
```
## Sorting
Columns may be sortable, by clicking on the column label. To make a column sortable, you must use the `sortable()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('name')
->sortable()
```
<AutoScreenshot name="tables/columns/sortable" alt="Table with sortable column" version="3.x" />
If you're using an accessor column, you may pass `sortable()` an array of database columns to sort by:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('full_name')
->sortable(['first_name', 'last_name'])
```
You may customize how the sorting is applied to the Eloquent query using a callback:
```php
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
TextColumn::make('full_name')
->sortable(query: function (Builder $query, string $direction): Builder {
return $query
->orderBy('last_name', $direction)
->orderBy('first_name', $direction);
})
```
## Sorting by default
You may choose to sort a table by default if no other sort is applied. You can use the `defaultSort()` method for this:
```php
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->columns([
// ...
])
->defaultSort('stock', 'desc');
}
```
### Persist sort in session
To persist the sorting in the user's session, use the `persistSortInSession()` method:
```php
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->columns([
// ...
])
->persistSortInSession();
}
```
## Searching
Columns may be searchable by using the text input field in the top right of the table. To make a column searchable, you must use the `searchable()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('name')
->searchable()
```
<AutoScreenshot name="tables/columns/searchable" alt="Table with searchable column" version="3.x" />
If you're using an accessor column, you may pass `searchable()` an array of database columns to search within:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('full_name')
->searchable(['first_name', 'last_name'])
```
You may customize how the search is applied to the Eloquent query using a callback:
```php
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
TextColumn::make('full_name')
->searchable(query: function (Builder $query, string $search): Builder {
return $query
->where('first_name', 'like', "%{$search}%")
->orWhere('last_name', 'like', "%{$search}%");
})
```
#### Customizing the table search field placeholder
You may customize the placeholder in the search field using the `searchPlaceholder()` method on the `$table`:
```php
use Filament\Tables\Table;
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->searchPlaceholder('Search (ID, Name)');
}
```
### Searching individually
You can choose to enable a per-column search input field using the `isIndividual` parameter:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('name')
->searchable(isIndividual: true)
```
<AutoScreenshot name="tables/columns/individually-searchable" alt="Table with individually searchable column" version="3.x" />
If you use the `isIndividual` parameter, you may still search that column using the main "global" search input field for the entire table.
To disable that functionality while still preserving the individual search functionality, you need the `isGlobal` parameter:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->searchable(isIndividual: true, isGlobal: false)
```
You may optionally persist the searches in the query string:
```php
use Livewire\Attributes\Url;
/**
* @var array<string, string | array<string, string | null> | null>
*/
#[Url]
public array $tableColumnSearches = [];
```
### Customizing the table search debounce
You may customize the debounce time in all table search fields using the `searchDebounce()` method on the `$table`. By default it is set to `500ms`:
```php
use Filament\Tables\Table;
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->searchDebounce('750ms');
}
```
### Searching when the input is blurred
Instead of automatically reloading the table contents while the user is typing their search, which is affected by the [debounce](#customizing-the-table-search-debounce) of the search field, you may change the behavior so that the table is only searched when the user blurs the input (tabs or clicks out of it), using the `searchOnBlur()` method:
```php
use Filament\Tables\Table;
public static function table(Table $table): Table
{
return $table
->columns([
// ...
])
->searchOnBlur();
}
```
### Persist search in session
To persist the table or individual column search in the user's session, use the `persistSearchInSession()` or `persistColumnSearchInSession()` method:
```php
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->columns([
// ...
])
->persistSearchInSession()
->persistColumnSearchesInSession();
}
```
## Column actions and URLs
When a cell is clicked, you may run an "action", or open a URL.
### Running actions
To run an action, you may use the `action()` method, passing a callback or the name of a Livewire method to run. Each method accepts a `$record` parameter which you may use to customize the behavior of the action:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->action(function (Post $record): void {
$this->dispatch('open-post-edit-modal', post: $record->getKey());
})
```
#### Action modals
You may open [action modals](../actions#modals) by passing in an `Action` object to the `action()` method:
```php
use Filament\Tables\Actions\Action;
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->action(
Action::make('select')
->requiresConfirmation()
->action(function (Post $record): void {
$this->dispatch('select-post', post: $record->getKey());
}),
)
```
Action objects passed into the `action()` method must have a unique name to distinguish it from other actions within the table.
### Opening URLs
To open a URL, you may use the `url()` method, passing a callback or static URL to open. Callbacks accept a `$record` parameter which you may use to customize the URL:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->url(fn (Post $record): string => route('posts.edit', ['post' => $record]))
```
You may also choose to open the URL in a new tab:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->url(fn (Post $record): string => route('posts.edit', ['post' => $record]))
->openUrlInNewTab()
```
## Setting a default value
To set a default value for columns with an empty state, you may use the `default()` method. This method will treat the default state as if it were real, so columns like [image](image) or [color](color) will display the default image or color.
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->default('No description.')
```
## Adding placeholder text if a column is empty
Sometimes you may want to display placeholder text for columns with an empty state, which is styled as a lighter gray text. This differs from the [default value](#setting-a-default-value), as the placeholder is always text and not treated as if it were real state.
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->placeholder('No description.')
```
<AutoScreenshot name="tables/columns/placeholder" alt="Column with a placeholder for empty state" version="3.x" />
## Hiding columns
To hide a column conditionally, you may use the `hidden()` and `visible()` methods, whichever you prefer:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('role')
->hidden(! auth()->user()->isAdmin())
// or
TextColumn::make('role')
->visible(auth()->user()->isAdmin())
```
### Toggling column visibility
Users may hide or show columns themselves in the table. To make a column toggleable, use the `toggleable()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('email')
->toggleable()
```
<AutoScreenshot name="tables/columns/toggleable" alt="Table with toggleable column" version="3.x" />
#### Making toggleable columns hidden by default
By default, toggleable columns are visible. To make them hidden instead:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('id')
->toggleable(isToggledHiddenByDefault: true)
```
#### Customizing the toggle columns dropdown trigger action
To customize the toggle dropdown trigger button, you may use the `toggleColumnsTriggerAction()` method, passing a closure that returns an action. All methods that are available to [customize action trigger buttons](../actions/trigger-button) can be used:
```php
use Filament\Tables\Actions\Action;
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->filters([
// ...
])
->toggleColumnsTriggerAction(
fn (Action $action) => $action
->button()
->label('Toggle columns'),
);
}
```
## Calculated state
Sometimes you need to calculate the state of a column, instead of directly reading it from a database column.
By passing a callback function to the `state()` method, you can customize the returned state for that column based on the `$record`:
```php
use App\Models\Order;
use Filament\Tables\Columns\TextColumn;
TextColumn::make('amount_including_vat')
->state(function (Order $record): float {
return $record->amount * (1 + $record->vat_rate);
})
```
## Tooltips
You may specify a tooltip to display when you hover over a cell:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->tooltip('Title')
```
<AutoScreenshot name="tables/columns/tooltips" alt="Table with column triggering a tooltip" version="3.x" />
This method also accepts a closure that can access the current table record:
```php
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Model;
TextColumn::make('title')
->tooltip(fn (Model $record): string => "By {$record->author->name}")
```
## Horizontally aligning column content
Table columns are aligned to the start (left in LTR interfaces or right in RTL interfaces) by default. You may change the alignment using the `alignment()` method, and passing it `Alignment::Start`, `Alignment::Center`, `Alignment::End` or `Alignment::Justify` options:
```php
use Filament\Support\Enums\Alignment;
use Filament\Tables\Columns\TextColumn;
TextColumn::make('email')
->alignment(Alignment::End)
```
<AutoScreenshot name="tables/columns/alignment" alt="Table with column aligned to the end" version="3.x" />
Alternatively, you may use shorthand methods like `alignEnd()`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('name')
->alignEnd()
```
## Vertically aligning column content
Table column content is vertically centered by default. You may change the vertical alignment using the `verticalAlignment()` method, and passing it `VerticalAlignment::Start`, `VerticalAlignment::Center` or `VerticalAlignment::End` options:
```php
use Filament\Support\Enums\VerticalAlignment;
use Filament\Tables\Columns\TextColumn;
TextColumn::make('name')
->verticalAlignment(VerticalAlignment::Start)
```
<AutoScreenshot name="tables/columns/vertical-alignment" alt="Table with column vertically aligned to the start" version="3.x" />
Alternatively, you may use shorthand methods like `verticallyAlignStart()`:
```php
use Filament\Support\Enums\VerticalAlignment;
use Filament\Tables\Columns\TextColumn;
TextColumn::make('name')
->verticallyAlignStart()
```
## Allowing column headers to wrap
By default, column headers will not wrap onto multiple lines, if they need more space. You may allow them to wrap using the `wrapHeader()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('name')
->wrapHeader()
```
## Controlling the width of columns
By default, columns will take up as much space as they need. You may allow some columns to consume more space than others by using the `grow()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('name')
->grow()
```
Alternatively, you can define a width for the column, which is passed to the header cell using the `style` attribute, so you can use any valid CSS value:
```php
use Filament\Tables\Columns\IconColumn;
IconColumn::make('is_paid')
->label('Paid')
->boolean()
->width('1%')
```
## Grouping columns
You group multiple columns together underneath a single heading using a `ColumnGroup` object:
```php
use Filament\Tables\Columns\ColumnGroup;
use Filament\Tables\Columns\IconColumn;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
public function table(Table $table): Table
{
return $table
->columns([
TextColumn::make('title'),
TextColumn::make('slug'),
ColumnGroup::make('Visibility', [
TextColumn::make('status'),
IconColumn::make('is_featured'),
]),
TextColumn::make('author.name'),
]);
}
```
The first argument is the label of the group, and the second is an array of column objects that belong to that group.
<AutoScreenshot name="tables/columns/grouping" alt="Table with grouped columns" version="3.x" />
You can also control the group header [alignment](#horizontally-aligning-column-content) and [wrapping](#allowing-column-headers-to-wrap) on the `ColumnGroup` object. To improve the multi-line fluency of the API, you can chain the `columns()` onto the object instead of passing it as the second argument:
```php
use Filament\Support\Enums\Alignment;
use Filament\Tables\Columns\ColumnGroup;
ColumnGroup::make('Website visibility')
->columns([
// ...
])
->alignment(Alignment::Center)
->wrapHeader()
```
## Custom attributes
The HTML of columns can be customized, by passing an array of `extraAttributes()`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('slug')
->extraAttributes(['class' => 'bg-gray-200'])
```
These get merged onto the outer `<div>` element of each cell in that column.
## Global settings
If you wish to change the default behavior of all columns globally, then you can call the static `configureUsing()` method inside a service provider's `boot()` method, to which you pass a Closure to modify the columns using. For example, if you wish to make all columns [`searchable()`](#searching) and [`toggleable()`](#toggling-column-visibility), you can do it like so:
```php
use Filament\Tables\Columns\Column;
Column::configureUsing(function (Column $column): void {
$column
->toggleable()
->searchable();
});
```
Additionally, you can call this code on specific column types as well:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::configureUsing(function (TextColumn $column): void {
$column
->toggleable()
->searchable();
});
```
Of course, you are still able to overwrite this on each column individually:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('name')
->toggleable(false)
```

View File

@@ -0,0 +1,526 @@
---
title: Text column
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
## Overview
Text columns display simple text from your database:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
```
<AutoScreenshot name="tables/columns/text/simple" alt="Text column" version="3.x" />
## Displaying as a "badge"
By default, the text is quite plain and has no background color. You can make it appear as a "badge" instead using the `badge()` method. A great use case for this is with statuses, where may want to display a badge with a [color](#customizing-the-color) that matches the status:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('status')
->badge()
->color(fn (string $state): string => match ($state) {
'draft' => 'gray',
'reviewing' => 'warning',
'published' => 'success',
'rejected' => 'danger',
})
```
<AutoScreenshot name="tables/columns/text/badge" alt="Text column as badge" version="3.x" />
You may add other things to the badge, like an [icon](#adding-an-icon).
## Displaying a description
Descriptions may be used to easily render additional text above or below the column contents.
You can display a description below the contents of a text column using the `description()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->description(fn (Post $record): string => $record->description)
```
<AutoScreenshot name="tables/columns/text/description" alt="Text column with description" version="3.x" />
By default, the description is displayed below the main text, but you can move it above using the second parameter:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->description(fn (Post $record): string => $record->description, position: 'above')
```
<AutoScreenshot name="tables/columns/text/description-above" alt="Text column with description above the content" version="3.x" />
## Date formatting
You may use the `date()` and `dateTime()` methods to format the column's state using [PHP date formatting tokens](https://www.php.net/manual/en/datetime.format.php):
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('created_at')
->dateTime()
```
You may use the `since()` method to format the column's state using [Carbon's `diffForHumans()`](https://carbon.nesbot.com/docs/#api-humandiff):
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('created_at')
->since()
```
## Number formatting
The `numeric()` method allows you to format an entry as a number:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('stock')
->numeric()
```
If you would like to customize the number of decimal places used to format the number with, you can use the `decimalPlaces` argument:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('stock')
->numeric(decimalPlaces: 0)
```
By default, your app's locale will be used to format the number suitably. If you would like to customize the locale used, you can pass it to the `locale` argument:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('stock')
->numeric(locale: 'nl')
```
Alternatively, you can set the default locale used across your app using the `Number::useLocale()` method in the `boot()` method of a service provider:
```php
use Illuminate\Support\Number;
Number::useLocale('nl');
```
## Currency formatting
The `money()` method allows you to easily format monetary values, in any currency:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('price')
->money('EUR')
```
There is also a `divideBy` argument for `money()` that allows you to divide the original value by a number before formatting it. This could be useful if your database stores the price in cents, for example:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('price')
->money('EUR', divideBy: 100)
```
By default, your app's locale will be used to format the money suitably. If you would like to customize the locale used, you can pass it to the `locale` argument:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('price')
->money('EUR', locale: 'nl')
```
Alternatively, you can set the default locale used across your app using the `Number::useLocale()` method in the `boot()` method of a service provider:
```php
use Illuminate\Support\Number;
Number::useLocale('nl');
```
## Limiting text length
You may `limit()` the length of the cell's value:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->limit(50)
```
You may also reuse the value that is being passed to `limit()`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->limit(50)
->tooltip(function (TextColumn $column): ?string {
$state = $column->getState();
if (strlen($state) <= $column->getCharacterLimit()) {
return null;
}
// Only render the tooltip if the column content exceeds the length limit.
return $state;
})
```
## Limiting word count
You may limit the number of `words()` displayed in the cell:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->words(10)
```
## Limiting text to a specific number of lines
You may want to limit text to a specific number of lines instead of limiting it to a fixed length. Clamping text to a number of lines is useful in responsive interfaces where you want to ensure a consistent experience across all screen sizes. This can be achieved using the `lineClamp()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->lineClamp(2)
```
## Adding a prefix or suffix
You may add a prefix or suffix to the cell's value:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('domain')
->prefix('https://')
->suffix('.com')
```
## Wrapping content
If you'd like your column's content to wrap if it's too long, you may use the `wrap()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->wrap()
```
## Listing multiple values
By default, if there are multiple values inside your text column, they will be comma-separated. You may use the `listWithLineBreaks()` method to display them on new lines instead:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('authors.name')
->listWithLineBreaks()
```
### Adding bullet points to the list
You may add a bullet point to each list item using the `bulleted()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('authors.name')
->listWithLineBreaks()
->bulleted()
```
### Limiting the number of values in the list
You can limit the number of values in the list using the `limitList()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('authors.name')
->listWithLineBreaks()
->limitList(3)
```
#### Expanding the limited list
You can allow the limited items to be expanded and collapsed, using the `expandableLimitedList()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('authors.name')
->listWithLineBreaks()
->limitList(3)
->expandableLimitedList()
```
Please note that this is only a feature for `listWithLineBreaks()` or `bulleted()`, where each item is on its own line.
### Using a list separator
If you want to "explode" a text string from your model into multiple list items, you can do so with the `separator()` method. This is useful for displaying comma-separated tags [as badges](#displaying-as-a-badge), for example:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('tags')
->badge()
->separator(',')
```
## Rendering HTML
If your column value is HTML, you may render it using `html()`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->html()
```
If you use this method, then the HTML will be sanitized to remove any potentially unsafe content before it is rendered. If you'd like to opt out of this behavior, you can wrap the HTML in an `HtmlString` object by formatting it:
```php
use Filament\Tables\Columns\TextColumn;
use Illuminate\Support\HtmlString;
TextColumn::make('description')
->formatStateUsing(fn (string $state): HtmlString => new HtmlString($state))
```
Or, you can return a `view()` object from the `formatStateUsing()` method, which will also not be sanitized:
```php
use Filament\Tables\Columns\TextColumn;
use Illuminate\Contracts\View\View;
TextColumn::make('description')
->formatStateUsing(fn (string $state): View => view(
'filament.tables.columns.description-entry-content',
['state' => $state],
))
```
### Rendering Markdown as HTML
If your column contains Markdown, you may render it using `markdown()`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('description')
->markdown()
```
## Custom formatting
You may instead pass a custom formatting callback to `formatStateUsing()`, which accepts the `$state` of the cell, and optionally its `$record`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('status')
->formatStateUsing(fn (string $state): string => __("statuses.{$state}"))
```
## Customizing the color
You may set a color for the text, either `danger`, `gray`, `info`, `primary`, `success` or `warning`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('status')
->color('primary')
```
<AutoScreenshot name="tables/columns/text/color" alt="Text column in the primary color" version="3.x" />
## Adding an icon
Text columns may also have an icon:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('email')
->icon('heroicon-m-envelope')
```
<AutoScreenshot name="tables/columns/text/icon" alt="Text column with icon" version="3.x" />
You may set the position of an icon using `iconPosition()`:
```php
use Filament\Support\Enums\IconPosition;
use Filament\Tables\Columns\TextColumn;
TextColumn::make('email')
->icon('heroicon-m-envelope')
->iconPosition(IconPosition::After) // `IconPosition::Before` or `IconPosition::After`
```
<AutoScreenshot name="tables/columns/text/icon-after" alt="Text column with icon after" version="3.x" />
The icon color defaults to the text color, but you may customize the icon color separately using `iconColor()`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('email')
->icon('heroicon-m-envelope')
->iconColor('primary')
```
<AutoScreenshot name="tables/columns/text/icon-color" alt="Text column with icon in the primary color" version="3.x" />
## Customizing the text size
Text columns have small font size by default, but you may change this to `TextColumnSize::ExtraSmall`, `TextColumnSize::Medium`, or `TextColumnSize::Large`.
For instance, you may make the text larger using `size(TextColumnSize::Large)`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->size(TextColumn\TextColumnSize::Large)
```
<AutoScreenshot name="tables/columns/text/large" alt="Text column in a large font size" version="3.x" />
## Customizing the font weight
Text columns have regular font weight by default, but you may change this to any of the following options: `FontWeight::Thin`, `FontWeight::ExtraLight`, `FontWeight::Light`, `FontWeight::Medium`, `FontWeight::SemiBold`, `FontWeight::Bold`, `FontWeight::ExtraBold` or `FontWeight::Black`.
For instance, you may make the font bold using `weight(FontWeight::Bold)`:
```php
use Filament\Support\Enums\FontWeight;
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
->weight(FontWeight::Bold)
```
<AutoScreenshot name="tables/columns/text/bold" alt="Text column in a bold font" version="3.x" />
## Customizing the font family
You can change the text font family to any of the following options: `FontFamily::Sans`, `FontFamily::Serif` or `FontFamily::Mono`.
For instance, you may make the font mono using `fontFamily(FontFamily::Mono)`:
```php
use Filament\Support\Enums\FontFamily;
use Filament\Tables\Columns\TextColumn;
TextColumn::make('email')
->fontFamily(FontFamily::Mono)
```
<AutoScreenshot name="tables/columns/text/mono" alt="Text column in a monospaced font" version="3.x" />
## Allowing the text to be copied to the clipboard
You may make the text copyable, such that clicking on the cell copies the text to the clipboard, and optionally specify a custom confirmation message and duration in milliseconds. This feature only works when SSL is enabled for the app.
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('email')
->copyable()
->copyMessage('Email address copied')
->copyMessageDuration(1500)
```
<AutoScreenshot name="tables/columns/text/copyable" alt="Text column with a button to copy it" version="3.x" />
### Customizing the text that is copied to the clipboard
You can customize the text that gets copied to the clipboard using the `copyableState()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('url')
->copyable()
->copyableState(fn (string $state): string => "URL: {$state}")
```
In this function, you can access the whole table row with `$record`:
```php
use App\Models\Post;
use Filament\Tables\Columns\TextColumn;
TextColumn::make('url')
->copyable()
->copyableState(fn (Post $record): string => "URL: {$record->url}")
```
## Displaying the row index
You may want a column to contain the number of the current row in the table:
```php
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Contracts\HasTable;
TextColumn::make('index')->state(
static function (HasTable $livewire, stdClass $rowLoop): string {
return (string) (
$rowLoop->iteration +
($livewire->getTableRecordsPerPage() * (
$livewire->getTablePage() - 1
))
);
}
),
```
As `$rowLoop` is [Laravel Blade's `$loop` object](https://laravel.com/docs/blade#the-loop-variable), you can reference all other `$loop` properties.
As a shortcut, you may use the `rowIndex()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('index')
->rowIndex()
```
To start counting from 0 instead of 1, use `isFromZero: true`:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('index')
->rowIndex(isFromZero: true)
```

View File

@@ -0,0 +1,115 @@
---
title: Icon column
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
## Overview
Icon columns render an [icon](https://blade-ui-kit.com/blade-icons?set=1#search) representing their contents:
```php
use Filament\Tables\Columns\IconColumn;
IconColumn::make('status')
->icon(fn (string $state): string => match ($state) {
'draft' => 'heroicon-o-pencil',
'reviewing' => 'heroicon-o-clock',
'published' => 'heroicon-o-check-circle',
})
```
In the function, `$state` is the value of the column, and `$record` can be used to access the underlying Eloquent record.
<AutoScreenshot name="tables/columns/icon/simple" alt="Icon column" version="3.x" />
## Customizing the color
Icon columns may also have a set of icon colors, using the same syntax. They may be either `danger`, `gray`, `info`, `primary`, `success` or `warning`:
```php
use Filament\Tables\Columns\IconColumn;
IconColumn::make('status')
->color(fn (string $state): string => match ($state) {
'draft' => 'info',
'reviewing' => 'warning',
'published' => 'success',
default => 'gray',
})
```
In the function, `$state` is the value of the column, and `$record` can be used to access the underlying Eloquent record.
<AutoScreenshot name="tables/columns/icon/color" alt="Icon column with color" version="3.x" />
## Customizing the size
The default icon size is `IconColumnSize::Large`, but you may customize the size to be either `IconColumnSize::ExtraSmall`, `IconColumnSize::Small`, `IconColumnSize::Medium`, `IconColumnSize::ExtraLarge` or `IconColumnSize::TwoExtraLarge`:
```php
use Filament\Tables\Columns\IconColumn;
IconColumn::make('status')
->size(IconColumn\IconColumnSize::Medium)
```
<AutoScreenshot name="tables/columns/icon/medium" alt="Medium-sized icon column" version="3.x" />
## Handling booleans
Icon columns can display a check or cross icon based on the contents of the database column, either true or false, using the `boolean()` method:
```php
use Filament\Tables\Columns\IconColumn;
IconColumn::make('is_featured')
->boolean()
```
> If this column in the model class is already cast as a `bool` or `boolean`, Filament is able to detect this, and you do not need to use `boolean()` manually.
<AutoScreenshot name="tables/columns/icon/boolean" alt="Icon column to display a boolean" version="3.x" />
### Customizing the boolean icons
You may customize the icon representing each state. Icons are the name of a Blade component present. By default, [Heroicons](https://heroicons.com) are installed:
```php
use Filament\Tables\Columns\IconColumn;
IconColumn::make('is_featured')
->boolean()
->trueIcon('heroicon-o-check-badge')
->falseIcon('heroicon-o-x-mark')
```
<AutoScreenshot name="tables/columns/icon/boolean-icon" alt="Icon column to display a boolean with custom icons" version="3.x" />
### Customizing the boolean colors
You may customize the icon color representing each state. These may be either `danger`, `gray`, `info`, `primary`, `success` or `warning`:
```php
use Filament\Tables\Columns\IconColumn;
IconColumn::make('is_featured')
->boolean()
->trueColor('info')
->falseColor('warning')
```
<AutoScreenshot name="tables/columns/icon/boolean-color" alt="Icon column to display a boolean with custom colors" version="3.x" />
## Wrapping multiple icons
When displaying multiple icons, they can be set to wrap if they can't fit on one line, using `wrap()`:
```php
use Filament\Tables\Columns\IconColumn;
IconColumn::make('icon')
->wrap()
```
Note: the "width" for wrapping is affected by the column label, so you may need to use a shorter or hidden label to wrap more tightly.

View File

@@ -0,0 +1,239 @@
---
title: Image column
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
## Overview
Images can be easily displayed within your table:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('avatar')
```
The column in the database must contain the path to the image, relative to the root directory of its storage disk.
<AutoScreenshot name="tables/columns/image/simple" alt="Image column" version="3.x" />
## Managing the image disk
By default, the `public` disk will be used to retrieve images. You may pass a custom disk name to the `disk()` method:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('header_image')
->disk('s3')
```
## Private images
Filament can generate temporary URLs to render private images, you may set the `visibility()` to `private`:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('header_image')
->visibility('private')
```
## Customizing the size
You may customize the image size by passing a `width()` and `height()`, or both with `size()`:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('header_image')
->width(200)
ImageColumn::make('header_image')
->height(50)
ImageColumn::make('author.avatar')
->size(40)
```
## Square image
You may display the image using a 1:1 aspect ratio:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('avatar')
->square()
```
<AutoScreenshot name="tables/columns/image/square" alt="Square image column" version="3.x" />
## Circular image
You may make the image fully rounded, which is useful for rendering avatars:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('avatar')
->circular()
```
<AutoScreenshot name="tables/columns/image/circular" alt="Circular image column" version="3.x" />
## Adding a default image URL
You can display a placeholder image if one doesn't exist yet, by passing a URL to the `defaultImageUrl()` method:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('avatar')
->defaultImageUrl(url('/images/placeholder.png'))
```
## Stacking images
You may display multiple images as a stack of overlapping images by using `stacked()`:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('colleagues.avatar')
->circular()
->stacked()
```
<AutoScreenshot name="tables/columns/image/stacked" alt="Stacked image column" version="3.x" />
### Customizing the stacked ring width
The default ring width is `3`, but you may customize it to be from `0` to `8`:
```php
ImageColumn::make('colleagues.avatar')
->circular()
->stacked()
->ring(5)
```
### Customizing the stacked overlap
The default overlap is `4`, but you may customize it to be from `0` to `8`:
```php
ImageColumn::make('colleagues.avatar')
->circular()
->stacked()
->overlap(2)
```
## Wrapping multiple images
Images can be set to wrap if they can't fit on one line, by setting `wrap()`:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('colleagues.avatar')
->circular()
->stacked()
->wrap()
```
Note: the "width" for wrapping is affected by the column label, so you may need to use a shorter or hidden label to wrap more tightly.
## Setting a limit
You may limit the maximum number of images you want to display by passing `limit()`:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('colleagues.avatar')
->circular()
->stacked()
->limit(3)
```
<AutoScreenshot name="tables/columns/image/limited" alt="Limited image column" version="3.x" />
### Showing the remaining images count
When you set a limit you may also display the count of remaining images by passing `limitedRemainingText()`.
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('colleagues.avatar')
->circular()
->stacked()
->limit(3)
->limitedRemainingText()
```
<AutoScreenshot name="tables/columns/image/limited-remaining-text" alt="Limited image column with remaining text" version="3.x" />
#### Showing the limited remaining text separately
By default, `limitedRemainingText()` will display the count of remaining images as a number stacked on the other images. If you prefer to show the count as a number after the images, you may use the `isSeparate: true` parameter:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('colleagues.avatar')
->circular()
->stacked()
->limit(3)
->limitedRemainingText(isSeparate: true)
```
<AutoScreenshot name="tables/columns/image/limited-remaining-text-separately" alt="Limited image column with remaining text separately" version="3.x" />
#### Customizing the limited remaining text size
By default, the size of the remaining text is `sm`. You can customize this to be `xs`, `md` or `lg` using the `size` parameter:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('colleagues.avatar')
->circular()
->stacked()
->limit(3)
->limitedRemainingText(size: 'lg')
```
## Custom attributes
You may customize the extra HTML attributes of the image using `extraImgAttributes()`:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('logo')
->extraImgAttributes(['loading' => 'lazy']),
```
You can access the current record using a `$record` parameter:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('logo')
->extraImgAttributes(fn (Company $record): array => [
'alt' => "{$record->name} logo",
]),
```
## Prevent file existence checks
When the table is loaded, it will automatically detect whether the images exist. This is all done on the backend. When using remote storage with many images, this can be time-consuming. You can use the `checkFileExistence(false)` method to disable this feature:
```php
use Filament\Tables\Columns\ImageColumn;
ImageColumn::make('attachment')
->checkFileExistence(false)
```

View File

@@ -0,0 +1,68 @@
---
title: Color column
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
## Overview
The color column allows you to show the color preview from a CSS color definition, typically entered using the color picker field, in one of the supported formats (HEX, HSL, RGB, RGBA).
```php
use Filament\Tables\Columns\ColorColumn;
ColorColumn::make('color')
```
<AutoScreenshot name="tables/columns/color/simple" alt="Color column" version="3.x" />
## Allowing the color to be copied to the clipboard
You may make the color copyable, such that clicking on the preview copies the CSS value to the clipboard, and optionally specify a custom confirmation message and duration in milliseconds. This feature only works when SSL is enabled for the app.
```php
use Filament\Tables\Columns\ColorColumn;
ColorColumn::make('color')
->copyable()
->copyMessage('Color code copied')
->copyMessageDuration(1500)
```
<AutoScreenshot name="tables/columns/color/copyable" alt="Color column with a button to copy it" version="3.x" />
### Customizing the text that is copied to the clipboard
You can customize the text that gets copied to the clipboard using the `copyableState()` method:
```php
use Filament\Tables\Columns\ColorColumn;
ColorColumn::make('color')
->copyable()
->copyableState(fn (string $state): string => "Color: {$state}")
```
In this function, you can access the whole table row with `$record`:
```php
use App\Models\Post;
use Filament\Tables\Columns\ColorColumn;
ColorColumn::make('color')
->copyable()
->copyableState(fn (Post $record): string => "Color: {$record->color}")
```
## Wrapping multiple color blocks
Color blocks can be set to wrap if they can't fit on one line, by setting `wrap()`:
```php
use Filament\Tables\Columns\ColorColumn;
ColorColumn::make('color')
->wrap()
```
Note: the "width" for wrapping is affected by the column label, so you may need to use a shorter or hidden label to wrap more tightly.

View File

@@ -0,0 +1,69 @@
---
title: Select column
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
## Overview
The select column allows you to render a select field inside the table, which can be used to update that database record without needing to open a new page or a modal.
You must pass options to the column:
```php
use Filament\Tables\Columns\SelectColumn;
SelectColumn::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
```
<AutoScreenshot name="tables/columns/select/simple" alt="Select column" version="3.x" />
## Validation
You can validate the input by passing any [Laravel validation rules](https://laravel.com/docs/validation#available-validation-rules) in an array:
```php
use Filament\Tables\Columns\SelectColumn;
SelectColumn::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
->rules(['required'])
```
## Disabling placeholder selection
You can prevent the placeholder from being selected using the `selectablePlaceholder()` method:
```php
use Filament\Tables\Columns\SelectColumn;
SelectColumn::make('status')
->options([
'draft' => 'Draft',
'reviewing' => 'Reviewing',
'published' => 'Published',
])
->selectablePlaceholder(false)
```
## Lifecycle hooks
Hooks may be used to execute code at various points within the select's lifecycle:
```php
SelectColumn::make()
->beforeStateUpdated(function ($record, $state) {
// Runs before the state is saved to the database.
})
->afterStateUpdated(function ($record, $state) {
// Runs after the state is saved to the database.
})
```

View File

@@ -0,0 +1,30 @@
---
title: Toggle column
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
## Overview
The toggle column allows you to render a toggle button inside the table, which can be used to update that database record without needing to open a new page or a modal:
```php
use Filament\Tables\Columns\ToggleColumn;
ToggleColumn::make('is_admin')
```
<AutoScreenshot name="tables/columns/toggle/simple" alt="Toggle column" version="3.x" />
## Lifecycle hooks
Hooks may be used to execute code at various points within the toggle's lifecycle:
```php
ToggleColumn::make()
->beforeStateUpdated(function ($record, $state) {
// Runs before the state is saved to the database.
})
->afterStateUpdated(function ($record, $state) {
// Runs after the state is saved to the database.
})
```

View File

@@ -0,0 +1,51 @@
---
title: Text input column
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
## Overview
The text input column allows you to render a text input inside the table, which can be used to update that database record without needing to open a new page or a modal:
```php
use Filament\Tables\Columns\TextInputColumn;
TextInputColumn::make('email')
```
<AutoScreenshot name="tables/columns/text-input/simple" alt="Text input column" version="3.x" />
## Validation
You can validate the input by passing any [Laravel validation rules](https://laravel.com/docs/validation#available-validation-rules) in an array:
```php
use Filament\Tables\Columns\TextInputColumn;
TextInputColumn::make('name')
->rules(['required', 'max:255'])
```
## Customizing the HTML input type
You may use the `type()` method to pass a custom [HTML input type](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#input_types):
```php
use Filament\Tables\Columns\TextInputColumn;
TextInputColumn::make('background_color')->type('color')
```
## Lifecycle hooks
Hooks may be used to execute code at various points within the input's lifecycle:
```php
TextInputColumn::make()
->beforeStateUpdated(function ($record, $state) {
// Runs before the state is saved to the database.
})
->afterStateUpdated(function ($record, $state) {
// Runs after the state is saved to the database.
})
```

View File

@@ -0,0 +1,30 @@
---
title: Checkbox column
---
import AutoScreenshot from "@components/AutoScreenshot.astro"
## Overview
The checkbox column allows you to render a checkbox inside the table, which can be used to update that database record without needing to open a new page or a modal:
```php
use Filament\Tables\Columns\CheckboxColumn;
CheckboxColumn::make('is_admin')
```
<AutoScreenshot name="tables/columns/checkbox/simple" alt="Checkbox column" version="3.x" />
## Lifecycle hooks
Hooks may be used to execute code at various points within the checkbox's lifecycle:
```php
CheckboxColumn::make()
->beforeStateUpdated(function ($record, $state) {
// Runs before the state is saved to the database.
})
->afterStateUpdated(function ($record, $state) {
// Runs after the state is saved to the database.
})
```

View File

@@ -0,0 +1,68 @@
---
title: Custom columns
---
import LaracastsBanner from "@components/LaracastsBanner.astro"
<LaracastsBanner
title="Build a Custom Table Column"
description="Watch the Build Advanced Components for Filament series on Laracasts - it will teach you how to build components, and you'll get to know all the internal tools to help you."
url="https://laracasts.com/series/build-advanced-components-for-filament/episodes/10"
series="building-advanced-components"
/>
## View columns
You may render a custom view for a cell using the `view()` method:
```php
use Filament\Tables\Columns\ViewColumn;
ViewColumn::make('status')->view('filament.tables.columns.status-switcher')
```
This assumes that you have a `resources/views/filament/tables/columns/status-switcher.blade.php` file.
## Custom classes
You may create your own custom column classes and cell views, which you can reuse across your project, and even release as a plugin to the community.
> If you're just creating a simple custom column to use once, you could instead use a [view column](#view-columns) to render any custom Blade file.
To create a custom column class and view, you may use the following command:
```bash
php artisan make:table-column StatusSwitcher
```
This will create the following column class:
```php
use Filament\Tables\Columns\Column;
class StatusSwitcher extends Column
{
protected string $view = 'filament.tables.columns.status-switcher';
}
```
It will also create a view file at `resources/views/filament/tables/columns/status-switcher.blade.php`.
## Accessing the state
Inside your view, you may retrieve the state of the cell using the `$getState()` function:
```blade
<div>
{{ $getState() }}
</div>
```
## Accessing the Eloquent record
Inside your view, you may access the Eloquent record using the `$getRecord()` function:
```blade
<div>
{{ $getRecord()->name }}
</div>
```

View File

@@ -0,0 +1,82 @@
---
title: Column relationships
---
## Displaying data from relationships
You may use "dot notation" to access columns within relationships. The name of the relationship comes first, followed by a period, followed by the name of the column to display:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('author.name')
```
## Counting relationships
If you wish to count the number of related records in a column, you may use the `counts()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('users_count')->counts('users')
```
In this example, `users` is the name of the relationship to count from. The name of the column must be `users_count`, as this is the convention that [Laravel uses](https://laravel.com/docs/eloquent-relationships#counting-related-models) for storing the result.
If you'd like to scope the relationship before calculating, you can pass an array to the method, where the key is the relationship name and the value is the function to scope the Eloquent query with:
```php
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
TextColumn::make('users_count')->counts([
'users' => fn (Builder $query) => $query->where('is_active', true),
])
```
## Determining relationship existence
If you simply wish to indicate whether related records exist in a column, you may use the `exists()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('users_exists')->exists('users')
```
In this example, `users` is the name of the relationship to check for existence. The name of the column must be `users_exists`, as this is the convention that [Laravel uses](https://laravel.com/docs/eloquent-relationships#other-aggregate-functions) for storing the result.
If you'd like to scope the relationship before calculating, you can pass an array to the method, where the key is the relationship name and the value is the function to scope the Eloquent query with:
```php
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
TextColumn::make('users_exists')->exists([
'users' => fn (Builder $query) => $query->where('is_active', true),
])
```
## Aggregating relationships
Filament provides several methods for aggregating a relationship field, including `avg()`, `max()`, `min()` and `sum()`. For instance, if you wish to show the average of a field on all related records in a column, you may use the `avg()` method:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('users_avg_age')->avg('users', 'age')
```
In this example, `users` is the name of the relationship, while `age` is the field that is being averaged. The name of the column must be `users_avg_age`, as this is the convention that [Laravel uses](https://laravel.com/docs/eloquent-relationships#other-aggregate-functions) for storing the result.
If you'd like to scope the relationship before calculating, you can pass an array to the method, where the key is the relationship name and the value is the function to scope the Eloquent query with:
```php
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Builder;
TextColumn::make('users_avg_age')->avg([
'users' => fn (Builder $query) => $query->where('is_active', true),
], 'age')
```

View File

@@ -0,0 +1,123 @@
---
title: Advanced columns
---
## Table column utility injection
The vast majority of methods used to configure columns accept functions as parameters instead of hardcoded values:
```php
use Filament\Tables\Columns\TextColumn;
TextColumn::make('status')
->color(fn (string $state): string => match ($state) {
'draft' => 'gray',
'reviewing' => 'warning',
'published' => 'success',
'rejected' => 'danger',
})
```
This alone unlocks many customization possibilities.
The package is also able to inject many utilities to use inside these functions, as parameters. All customization methods that accept functions as arguments can inject utilities.
These injected utilities require specific parameter names to be used. Otherwise, Filament doesn't know what to inject.
### Injecting the current state of a column
If you wish to access the current state (value) of the column, define a `$state` parameter:
```php
function ($state) {
// ...
}
```
### Injecting the current Eloquent record
If you wish to access the current Eloquent record of the column, define a `$record` parameter:
```php
use Illuminate\Database\Eloquent\Model;
function (Model $record) {
// ...
}
```
Be aware that this parameter will be `null` if the column is not bound to an Eloquent record. For instance, the `label()` method of a column will not have access to the record, as the label is not related to any table row.
### Injecting the current column instance
If you wish to access the current column instance, define a `$column` parameter:
```php
use Filament\Tables\Columns\Column;
function (Column $column) {
// ...
}
```
### Injecting the current Livewire component instance
If you wish to access the current Livewire component instance that the table belongs to, define a `$livewire` parameter:
```php
use Filament\Tables\Contracts\HasTable;
function (HasTable $livewire) {
// ...
}
```
### Injecting the current table instance
If you wish to access the current table configuration instance that the column belongs to, define a `$table` parameter:
```php
use Filament\Tables\Table;
function (Table $table) {
// ...
}
```
### Injecting the current table row loop
If you wish to access the current [Laravel Blade loop object](https://laravel.com/docs/blade#the-loop-variable) that the column is rendered part of, define a `$rowLoop` parameter:
```php
function (stdClass $rowLoop) {
// ...
}
```
As `$rowLoop` is [Laravel Blade's `$loop` object](https://laravel.com/docs/blade#the-loop-variable), you can access the current row index using `$rowLoop->index`. Similar to `$record`, this parameter will be `null` if the column is currently being rendered outside a table row.
### Injecting multiple utilities
The parameters are injected dynamically using reflection, so you are able to combine multiple parameters in any order:
```php
use Filament\Tables\Contracts\HasTable;
use Illuminate\Database\Eloquent\Model;
function (HasTable $livewire, Model $record) {
// ...
}
```
### Injecting dependencies from Laravel's container
You may inject anything from Laravel's container like normal, alongside utilities:
```php
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
function (Request $request, Model $record) {
// ...
}
```