Table Classes
Every table extends Forjed\InertiaTable\Table and implements one required method: columns().
Creating a Table
php
use Forjed\InertiaTable\Table;
use Forjed\InertiaTable\Column;
class ServerTable extends Table
{
protected function columns(): array
{
return [
Column::make('name', 'Name')->sortable()->text(),
Column::make('ip', 'IP Address')->sortable(),
Column::data('id'),
];
}
}Properties
| Property | Type | Default | Description |
|---|---|---|---|
$defaultSort | string | 'created_at' | Default sort column |
$defaultSortDir | string | 'desc' | Default sort direction |
$perPage | int | 10 (from config) | Rows per page |
$pageName | string | 'page' | Query parameter name for pagination |
$tableSettings | array | [] | Extension metadata for the frontend |
Instantiation
The constructor accepts Eloquent\Builder, Query\Builder, or Relation instances:
php
// Static factory (recommended)
ServerTable::make(Server::query());
// With scopes
ServerTable::make(Server::where('active', true));
// With relations
ServerTable::make($project->servers());Fluent Setters
php
ServerTable::make(Server::query())
->perPage(25)
->pageName('serversPage') // for multi-table pages
->withSettings(['key' => 'value']) // extension metadata
->paginate();Output Methods
For Inertia (paginated response)
| Method | Description |
|---|---|
->paginate() | Full pagination - includes total count and last_page |
->simplePaginate() | Simple pagination - no COUNT(*) query, faster |
php
// In your controller
return Inertia::render('Servers', [
'servers' => ServerTable::make(Server::query())->paginate(),
]);For raw data (no pagination)
| Method | Description |
|---|---|
->toArray() | All matching rows as a flat array |
->toCollection() | All matching rows as a Laravel Collection |
Both apply search and sorting but skip pagination. Optional take and skip parameters for chunking:
php
// All rows
$rows = ServerTable::make(Server::query())->toArray();
// As a Collection
$rows = ServerTable::make(Server::query())->toCollection();
// With take/skip
$chunk = ServerTable::make(Server::query())->toArray(take: 100, skip: 200);Searchable Fields
Override searchable() to enable global search:
php
protected function searchable(): array
{
return ['name', 'ip', 'hostname'];
}Return [] (the default) to disable search.