tranquil-tools / laravel-table-builder
Define Laravel tables in PHP: columns, filters, search, sorting, bulk and row actions, export and reordering, independent of any frontend
Package info
github.com/ComfyCodersBV/laravel-table-builder
pkg:composer/tranquil-tools/laravel-table-builder
Requires
- php: ^8.3
- illuminate/contracts: ^11.0||^12.0||^13.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- kirschbaum-development/eloquent-power-joins: ^4.3
- larastan/larastan: ^3.0
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.8
- orchestra/testbench: ^9.0.0||^10.0.0||^11.0.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
- spatie/laravel-query-builder: ^7.3
Suggests
- kirschbaum-development/eloquent-power-joins: Required to enable support sorting by (nested) relationships in Tables (^4.0)
- spatie/laravel-query-builder: Build a table on a Spatie QueryBuilder for its filters and sorts (^7.0)
Provides
None
Conflicts
None
Replaces
None
README
Define Laravel tables in PHP: columns, filters, search, sorting, pagination, totals, bulk and row actions, CSV export and reordering. This package knows nothing about any frontend — it produces a JSON payload that a renderer consumes, and serves the signed bulk-action, reorder and export endpoints.
You probably want the Vue package instead
Unless you are writing a renderer, install tranquil-tools/laravel-vue-table-builder. It requires this package, so you get both:
composer require tranquil-tools/laravel-vue-table-builder
Full documentation lives at
docs.comfycoders.nl. This package ships no docs/ directory
on purpose: one documentation site, one version stream, no duplication.
What lives here
src/ |
AbstractTable, TableBuilder, QueryBuilder, components, export, the make:table command |
src/Http/, routes/ |
the signed table.bulk-action, table.reorder and table.export endpoints |
config/table-builder.php |
per page defaults, route middleware, signature lifetime, display timezone, export options |
resources/lang/ |
texts the payload carries, such as the search label and date presets |
The boundary rule: what produces the payload belongs here, what renders it belongs in a renderer.
Normalizing the search term
A search input takes a normalize callable that transforms the typed term before it is applied, so a phone number
typed as 06 1234 5678 finds 0612345678. It runs on the whole term, before the term is split into words. A result
that is empty skips the search input, but still counts as an active search filter. The payload keeps the value as typed,
so the schema does not change.
normalizeSearch on column() only works together with searchable: true. A global search bar has one normalizer for
all its columns: when columns need different normalizers, register a separate searchInput() per column.
$table->column('phone', searchable: true, normalizeSearch: fn (string $term) => str_replace(' ', '', $term)); $table->withGlobalSearch(columns: ['phone', 'name'], normalize: fn (string $term) => trim($term)); $table->searchInput(key: 'phone', normalize: fn (string $term) => preg_replace('/\D/', '', $term));
Linking a cell
A column takes a url callable that receives the row and returns the url its cell links to, or null for no link on
that row. The url is resolved from the rows already loaded, so it adds no queries. A renderer shows the cell as a link
that does not trigger the row link.
$table->column('subscribed_count', url: fn (MailingList $list) => route('subscribers.index', [ 'filter' => ['list' => $list->id], ]));
Table density
A table takes density('normal'|'compact'). compact asks the renderer for smaller cell and header padding, so more
rows fit on screen. Set it for every table of the app in a service provider; a table's own density() still wins.
TableBuilder::defaultDensity('compact'); $table->density('normal');
The schema contract
TableBuilder::SCHEMA_VERSION is emitted as schemaVersion in every payload. A renderer compares it against the
version it supports. Bump the major for changes that would misrender in an older renderer, the minor for additions
that can be ignored safely.
Payload additions per version
- 1.11 (schema 1.9): tables take
density('normal'|'compact'), sent asdensity;TableBuilder::defaultDensity()sets it app-wide. - 1.10 (schema 1.8): columns take a
urlcallable. The payload carriescolumnLinks, per row a map of column key to url, in the same order asrowLinks. - 1.9 (schema 1.7):
rowLink()takes amethod, sent asrowLinkMethod(getby default). A non-GET row link cannot be a modal, a plain href or open in a new tab. - 1.7 (schema 1.6): tables take
searchPlacement('inline'|'above'), sent assearchPlacement;TableBuilder::defaultSearchPlacement()sets it app-wide. - 1.6 (schema 1.5): tables take
bulkActionsAlwaysVisible(), sent asbulkActionsAlwaysVisible. - 1.5 (schema 1.4): columns take
headerClassesandhideBelow(head_classandhide_belowin the payload); tables takegridBelow(), sent asgridBelow. - 1.4 (schema 1.3): every resolved row action carries
rowKey, the row key of its row (the same value as the row's__key), so a consumer matches an action to its row without parsing the url. - 1.3 (schema 1.2): row actions take
iconOnly, withrowActionsIconOnly()per table andTableBuilder::defaultRowActionsIconOnly()/TableBuilder::defaultRowActionIcons()for the app. Tables takegrid(),layout()andlayoutToggle(); the payload carrieslayout,defaultLayout,layoutToggleandqueryKeys.layout. - 1.2 (schema 1.1): row actions take
icon.
The full usage lives in the documentation of the Vue package: row actions, columns and grid layout.
Coming from laravel-vue-table-builder
The namespace TranquilTools\TableBuilder\ did not change, so table classes keep working. Exactly one installed
package may claim that namespace: this one.
- Configuration lives in
config/table-builder.php. A publishedconfig/vue-table-builder.phpis still read and wins over the defaults, andconfig('vue-table-builder.*')still resolves. Rename the file when convenient. - Translations live under
table-builder::;vue-table-builder::keeps resolving to the same files. Overrides published inlang/vendor/vue-table-builderkeep applying until alang/vendor/table-builderdirectory exists.
Credits
Built by ComfyCoders BV. Licensed under MIT — see LICENSE.md.