Overview
Introduction
Column classes can be found in the Filament\Tables\Columns
namespace. They reside within the $table->columns()
method. Filament includes a number of columns built-in:
Editable columns allow the user to update data in the database without leaving the table:
You may also create your own custom columns to display data however you wish.
Columns may be created using the static make()
method, passing its unique name. Usually, the name of a column corresponds to the name of an attribute on an Eloquent model. You may use "dot notation" to access attributes within relationships:
use Filament\Tables\Columns\TextColumn;
TextColumn::make('title')
TextColumn::make('author.name')
Column content (state)
Columns may feel a bit magic at first, but they are designed to be simple to use and optimized to display data from an Eloquent record. Despite this, they are flexible and you can display data from any source, not just an Eloquent record attribute.
The data that a column displays is called its "state". When using a panel resource, the table is aware of the records it is displaying. This means that the state of the column is set based on the value of the attribute on the record. For example, if the column is used in the table of a PostResource
, then the title
attribute value of the current post will be displayed.
use Filament\Tables\Components\TextColumn;
TextColumn::make('title')
If you want to access the value stored in a relationship, you can use "dot notation". The name of the relationship that you would like to access data from comes first, followed by a dot, and then the name of the attribute:
use Filament\Tables\Components\TextColumn;
TextColumn::make('author.name')
You can also use "dot notation" to access values within a JSON / array column on an Eloquent model. The name of the attribute comes first, followed by a dot, and then the key of the JSON object you want to read from:
use Filament\Tables\Components\TextColumn;
TextColumn::make('meta.title')
Setting the state of a column
You can pass your own state to a column by using the state()
method:
use Filament\Tables\Components\TextColumn;
TextColumn::make('title')
->state('Hello, world!')
The state()
method also accepts a function to dynamically calculate the state. You can inject various utilities into the function as parameters.
Learn more about utility injection.Utility | Type | Parameter | Description |
---|---|---|---|
Column | Filament\Tables\Columns\Column | $column | The current column instance. |
Livewire | Livewire\Component | $livewire | The Livewire component instance. |
Eloquent record | ?Illuminate\Database\Eloquent\Model | $record | The Eloquent record for the current table row. |
Row loop | stdClass | $rowLoop | The <a href="https://laravel.com/docs/blade#the-loop-variable" target="_blank">row loop</a> object for the current table row. |
State | mixed | $state | The current value of the column, based on the current table row. |
Table | Filament\Tables\Table | $table | The current table instance. |