Skip to content

Data sources

Pass an Eloquent builder to keep filtering, search, sorting, and pagination in the database:

UsersTable::make('users')->data(
User::query()->where('account_id', $account->id),
);

Scope the query to records the current user may view. See Authorization & security.

Add a protected data() method when the query belongs with the table definition:

protected function data(): mixed
{
return User::query()->whereKey(auth()->id());
}

A fluent ->data($query) call overrides this method’s result.

To resolve a source later, pass a closure:

UsersTable::make('users')->data(
fn () => User::query()->whereKey(auth()->id()),
);

data() also accepts arrays, Laravel collections, Eloquent collections, and model class names. Use Collections & arrays for a complete in-memory example.

UsersTable::make('users')->data(User::class);

Every row needs a stable, unique key. Eloquent queries use the model’s primary key; ordinary arrays and collections use id. Choose another field with rowKey():

use InertiaX\Components\Table\Columns\TextColumn;
use InertiaX\Facades\InertiaX;
InertiaX::table('sessions')
->data($sessions)
->rowKey('uuid')
->addColumns([
TextColumn::make('uuid')->visible(false),
TextColumn::make('ip_address', 'IP address'),
]);

The key must be a declared column, including for empty results. Use a persistent identifier, not a position that changes when rows are sorted or filtered.

See Table API for model collections, integer limits, and validation.