Laravel Livewire Tables Documentation

🎉 Enjoying this package? Consider sponsoring me on GitHub or buying me a beer.

This is the documentation for v1 but the latest version is v3. You can switch versions in the menu at the top. Check your current version with the following command:

composer show rappasoft/laravel-livewire-tables

Making Columns

Defining columns is required in every DataTable regardless of if you're using built-in or custom features.

You define columns in the columns() method using the Column class, you must have one column object for every table header, even if it is blank (see making blank columns).

1public function columns(): array
2{
3 return [
4 Column::make('Type'),
5 Column::make('Name'),
6 Column::make('E-mail'),
7 Column::make('Permissions'),
8 ];
9}

The Column class takes two parameters, the first is the display title of the column header, the second is the database column or relationship name and column for sorting and searching purposes.

If you leave it blank, the component will use the snake_case version of the title.

For example:

1public function columns(): array
2{
3 return [
4 Column::make('Type'), // column = type
5 Column::make('Name'), // column = name
6 Column::make('E-mail'), // column = e-mail <- BAD
7 Column::make('Permissions'), // column = permissions
8 ];
9}

As you can see above, E-mail contains a special character and therefore does not directly translate to the column name, so you would specify it as the second parameter:

1Column::make('E-mail', 'email'),

To pull from a relationship, you can use the dot syntax:

1Column::make('Permissions', 'abilities.permissions'),