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.
A parent’s related rows
Section titled “A parent’s related rows”OrdersTable::make('customer-orders')->data($customer->orders());Pass a standard Eloquent HasMany relation to show only that parent’s related rows. Its
query constraints, model scopes, and selected fields are preserved; table operations leave
the supplied relation unchanged. You can also return the relation from a protected data()
method or deferred closure.
Other relation types and custom HasMany subclasses are unsupported. See
Source types for the exact boundary and failure behavior.
Define data in the class
Section titled “Define data in the class”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()),);Other sources
Section titled “Other sources”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);For an API, search service, or repository that owns retrieval, pass a TableSource through
the same data() method. See Custom sources for a working adapter.
Row identity
Section titled “Row identity”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\Table\Columns\TextColumn;use InertiaX\Table\Table;
Table::make('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.
Related fields and aggregates
Section titled “Related fields and aggregates”Use relationship() for a persisted scalar field
through a standard, single-hop BelongsTo relation. Use
count() and sum() for standard, single-hop
HasMany aggregates. These helpers bind the displayed value and built-in comparisons to the
same query field. Enable sorting and filtering separately; related text fields can also enable search.
For other relation types or query shapes, use ordinary Eloquent capabilities such as correlated
subqueries, withCount() or withSum(). Declare the resulting field as a column and use
sortUsing() or searchUsing() for its query behavior. A displayed alias alone does not define
relationship search or sorting.
A customer_name subselect can display a related name while a search callback uses
whereHas('customer', ...). See Custom query behavior for source
strategies and Callback context for their arguments.
For an external service that owns filtering and pagination, use a
custom source instead.