Relationship Types

Display data from relationship types: hasOne, belongsTo, hasMany, belongsToMany, and nested relationships.

ArrayColumn::make('Articles', 'id')->data(...)->outputFormat(...)
Articles Article Count Tags
1 Miss Eve Will [email protected] 769 Haven Course Lake Hipolito, NV 61850 No parent West Angelita Alice a little., Majesty?' he. 18 articles South Barttown Winonaland Miafort South Corrineville New Keltonborough Dorris Hegmann
2 Mr. Cornelius Hansen DDS [email protected] 8049 Ledner Rapid Apt. 014 North Nathaniel, SC 18886-9393 No parent Kohlerport By the use., VERY much. 25 articles Winonaland South Elta Chauncey Schmidt
3 Dr. Albertha Abbott [email protected] 7778 Erick Passage Blandamouth, ND 34081 No parent North Ayla After a time she., Alice, that. 9 articles East Abnerborough South Barttown Miafort Craigbury Arlie Labadie Jr.
4 Citlalli Berge PhD [email protected] No address No parent No city The Dormouse had., Alice in. 25 articles Zboncakstad Jaskolskihaven Odaland No group
5 Mr. Austen Harber [email protected] 5157 Mayer Throughway Apt. 950 Cyrilhaven, NV 65970 No parent Kohlerport Then they., ARE OLD, FATHER. 25 articles West Larissaburgh Miafort South Elta Lake Emmaside Mariemouth Chauncey Schmidt
6 Raegan Pfannerstill PhD [email protected] 16411 Tressie Square West Phyllismouth, HI 89056 No parent North Ayla Alice, as the jury., Next came the. 16 articles East Abnerborough South Barttown Keeblermouth Robelberg Arlie Labadie Jr.
7 Dan Ebert [email protected] No address No parent No city SOME change in., QUITE as much use. 20 articles Shyannside Craigbury No group
8 Mertie Kohler [email protected] No address No parent No city Father William,'., Alice had. 21 articles Cartwrighthaven South Elta Jaskolskihaven Craigbury No group
9 Prof. Cornelius Herzog DDS [email protected] 563 Ortiz Prairie Suite 942 Lake Damarismouth, MN 84789 Mr. Austen Harber South Tomasfurt By the use of a., There could be NO. 13 articles East Abnerborough West Larissaburgh Mariemouth East Ewellstad Odaland Prof. Bernie O'Conner
10 Barbara Metz [email protected] 918 Waelchi View Suite 490 Colehaven, KY 64041-2304 Mr. Cornelius Hansen DDS Lake Orvillestad I don't think,'., Alice could not. 24 articles Cartwrighthaven Rosa Schmeler
hasOne belongsTo Nested: address.group.city hasMany Custom formatter belongsToMany nested (hasOneThrough n/a)

Showing 1 to 10 of results

Not available in v3

  • heading() / description() — no table-level heading API. The heading above is rendered by the page layout; for markup inside the table wrapper use setConfigurableArea('before-toolbar', 'view.path').
  • displayField(), separator(), limit() and formatRelations() on a plain Column — use ArrayColumn with data() + outputFormat() (limit by calling take() inside data()), or a label() column.
  • relationshipSeparator() — separator() exists, but only on ArrayColumn.
  • hasOneThrough / hasManyThrough columns — v3 only builds joins for hasOne, belongsTo and morphOne, so "through" relations cannot be used with dot notation. The Address Group column below walks the nested address.group relation instead.

✨ Overview

Livewire Tables supports all Laravel relationship types, allowing you to display and interact with related model data directly in your table columns. This includes hasOne, belongsTo, hasMany, belongsToMany, hasManyThrough, hasOneThrough, and nested relationships.

1 hasOne Relationship

Display data from a single related model using dot notation:

// User hasOne Address
Column::make('Address', 'address.address')
    ->sortable()
    ->searchable(),

// In builder, eager load:
public function builder(): Builder
{
    return User::query()->with('address');
}

2 belongsTo Relationship

Access parent model data:

// User belongsTo Parent (self-referencing)
Column::make('Parent', 'parent.name')
    ->sortable()
    ->searchable(),

public function builder(): Builder
{
    return User::query()->with('parent');
}

3 Nested Relationships

Navigate through multiple relationship levels:

// User → Address → Group → City
Column::make('City', 'address.group.city.name')
    ->sortable()
    ->searchable(),

public function builder(): Builder
{
    return User::query()->with('address.group.city');
}

4 hasMany Relationship

Display collections from hasMany relationships:

// User hasMany Articles
ArrayColumn::make('Articles', 'id')
    ->data(fn($value, $row) => $row->articles->take(3)) // limit here
    ->outputFormat(fn($index, $value) => e($value->title))
    ->separator(', '),

// Or with a custom formatter, via a label column
Column::make('Article Count')
    ->label(fn($row) => $row->articles->count() . ' articles'),

public function builder(): Builder
{
    return User::query()->with('articles');
}

5 belongsToMany Relationship

Display many-to-many relationship collections:

// User belongsToMany Tags
ArrayColumn::make('Tags', 'id')
    ->data(fn($value, $row) => $row->tags)
    ->outputFormat(fn($index, $value) => '<span class="badge">' . e($value->name) . '</span>')
    ->separator(' '),

public function builder(): Builder
{
    return User::query()->with('tags');
}

6 hasOneThrough / hasManyThrough (not supported)

v3 cannot join "through" relationships, so walk the intermediate relations with dot notation instead:

// User → Address → AddressGroup (via the nested relations)
Column::make('Address Group', 'address.group.name')
    ->sortable(),

public function builder(): Builder
{
    return User::query()->with('address.group');
}

7 Collection Display Options

Customize how collections are displayed:

ArrayColumn::make('Articles', 'id')
    ->data(fn($value, $row) => $row->articles->take(5)) // limit displayed items
    ->outputFormat(fn($index, $value) => // per-item formatter
        '<span class="badge">' . e($value->title) . '</span>'
    )
    ->separator(' | ')             // Custom separator
    ->emptyValue('None')           // Shown when the collection is empty
    ->flexRow(['class' => 'gap-1']), // Optional wrapper

⚠️ Important: Eager Loading

Always eager load relationships to avoid N+1 query problems:

// ✅ Correct - eager load all relationships
public function builder(): Builder
{
    return User::query()
        ->with([
            'address',
            'address.group.city',
            'parent',
            'articles',
            'tags',
            'addressgroup',
        ]);
}

// ❌ Wrong - will cause N+1 queries
public function builder(): Builder
{
    return User::query(); // Missing ->with()
}

Tip: Enable throw_exception_on_unloaded_relationships in config to catch N+1 issues during development.

Key Benefits

  • All Relationship Types — Supports hasOne, belongsTo, hasMany, belongsToMany, hasOneThrough, hasManyThrough, and nested relationships
  • Collection Formatting — Customize how collections are displayed with separators, limits, and formatters
  • Sortable & Searchable — All relationship columns can be sorted and searched
  • Nullable Support — Gracefully handles missing relationships with empty string fallback