Creating Columns

The columns method on your component must return an array of Column objects in the order you wish to see them on the table:

1public function columns(): array
2{
3 return [
4 Column::make('Name'),
5 Column::make('Email'),
6 ];
7}

Setting field names

By default, you only need one parameter which acts as the header of the column, the field which it references will be acquired using Str::snake.

So if you have:

1public function columns(): array
2{
3 return [
4 Column::make('Name'), // Looks for column `name`
5 Column::make('Email'), // Looks for column `email`
6 ];
7}

Of course, this won't work in every situation, for example if you have an ID column, Str::snake will convert it to i_d which is incorrect. For this situation and any other situation where you want to specify the field name, you can pass it as the second parameter:

1public function columns(): array
2{
3 return [
4 Column::make('ID', 'id'),
5 Column::make('E-mail', 'email'),
6 ];
7}