---
title: Tables
published: 2026-10-19
lastmod: 2026-10-19
url: https://larasell.dev/docs/admin/reference/tables
---

## Table of contents
- [Defining a table](#defining-a-table)
- [Adding columns](#adding-columns)
  - [Labelling columns](#labelling-columns)
  - [Formatting values](#formatting-values)
  - [Adding images](#adding-images)
- [Displaying the table](#displaying-the-table)
- [Row links](#row-links)
- [Header actions](#header-actions)
- [Table title](#table-title)
- [Empty states](#empty-states)

# Tables

You can use tables to extend the admin panel by writing PHP and never
touching TypeScript or CSS. This page covers how to create tables and then
how to display them in the admin panel.

## Defining a table

Use the following command to scaffold the code for a table:

```bash
php artisan make:larasell-table ProductReviewTable
```

The command creates the following code:

```php
namespace App\Tables;

use Larasell\Admin\Tables\Table;

class ProductReviewTable extends Table
{
    public function columns(): array
    {
        return [
            //
        ];
    }
}
```

The `UseModel` attribute sets the Eloquent model the table lists. You can also set the model with a `$model` property:

```php
protected ?string $model = ProductReview::class;
```

## Adding columns

To add columns, use
the `TextColumn`{href="https://raw.githubusercontent.com/Larasell-dev/admin/refs/heads/main/src/Tables/Columns/TextColumn.php"} class:

```php
namespace App\Tables;

use Larasell\Admin\Tables\Columns\TextColumn;
use Larasell\Admin\Tables\Table;

class ProductReviewTable extends Table
{
    public function columns(): array
    {
        return [
           TextColumn::make('author'),
           TextColumn::make('rating'),
           TextColumn::make('body', 'Review'),
        ];
    }
}
```

When you pass the `make` method a string, the column shows the property of the Eloquent model.

The columns appear in the order you add them. To re-order them, move
the classes around in the array.

### Labelling columns

The second parameter allows you to define a label. The label is optional.
When you don't pass a label, `Table`{href="https://raw.githubusercontent.com/Larasell-dev/admin/refs/heads/main/src/Tables/Table.php"} infers it. `author` turns into "Author" and
multi-word strings, like `product-review`, `product_review` or `productReview`, turn
into "Product review".

### Formatting values

Use `map` to change what a column shows. The callback receives the value and the record:

```php
TextColumn::make('rating')->map(fn (int $rating) => str_repeat('★', $rating)),
TextColumn::make('author')->map(fn ($value, ProductReview $review) => $review->user->name),
```

The column doesn't have to be an attribute of the model, so you can compute a column from other attributes.

The callback must return text, a number or `null`. Anything else, like a boolean, throws an exception.

### Adding images

Use `image` to show an icon or a picture before a cell's value. The callback receives the record
and an `Image`{href="https://raw.githubusercontent.com/Larasell-dev/admin/refs/heads/main/src/Tables/Columns/Image.php"}, and returns the image to show:

```php
use App\Models\ProductReview;
use Larasell\Admin\Enums\Icon;
use Larasell\Admin\Tables\Columns\Image;
use Larasell\Admin\Tables\Columns\TextColumn;
use Larasell\Admin\Tables\Table;

class ProductReviewTable extends Table
{
    public function columns(): array
    {
        return [
            TextColumn::make('author')
                ->image(function (ProductReview $review, Image $image) {
                    return $image
                        ->url($review->user->avatar_url)
                        ->rounded();
                }),
            TextColumn::make('rating')
                ->image(function (ProductReview $review, Image $image) {
                    return $image->icon(Icon::Star);
                }),
        ];
    }
}
```

`icon` accepts an `Icon`{href="https://raw.githubusercontent.com/Larasell-dev/admin/refs/heads/main/src/Enums/Icon.php"} enum case or a [Remix icon](https://remixicon.com) name.
`url` takes the address of a picture. To show a picture your app serves, use `route`,
`signedRoute` or `temporarySignedRoute`. They take the same arguments as Laravel's URL helpers of
the same name:

```php
// A picture at a named route
$image->route('avatars.show', $review->user);

// A picture behind a signed URL
$image->signedRoute('avatars.show', $review->user);

// A picture behind a signed URL that expires after an hour
$image->temporarySignedRoute(
    'avatars.show',
    now()->addHour(),
    $review->user,
);
```

Pictures are square. Call `rounded` to show them as a circle, for example for avatars.

Return `null` to show no image for a row:

```php
TextColumn::make('author')
    ->image(function (ProductReview $review, Image $image) {
        if ($review->user->avatar_url === null) {
            return null;
        }

        return $image
            ->url($review->user->avatar_url)
            ->rounded();
    }),
```

When an image tells the user something the text doesn't, describe it with `alt` for screen
readers. Use `title` to show a tooltip when the user hovers over the image:

```php
$image
    ->icon(Icon::Star)
    ->alt('Verified purchase')
    ->title('Verified purchase');
```

## Displaying the table

Use the `index` method of the `Navigation`{href="https://raw.githubusercontent.com/Larasell-dev/admin/refs/heads/main/src/Facades/Navigation.php"} facade inside `routes/admin.php`
to show the table on its own page and link to it from the sidebar:

```php
use App\Tables\ProductReviewTable;
use Larasell\Admin\Enums\Icon;
use Larasell\Admin\Facades\Navigation;

Navigation::index(
    'Reviews',
    'reviews',
    ProductReviewTable::class,
    Icon::Star,
);
```

It takes a label, a URI, the table class and an icon. The table shows up at `/admin/reviews`,
on a route named `larasell.admin.reviews.index`, and the sidebar gets a "Reviews" item that
links to it.

Adding the table to the navigation is optional. To only register the page, and link to it
yourself like any other route, use `Route::index`{href="https://raw.githubusercontent.com/Larasell-dev/admin/refs/heads/main/src/AdminServiceProvider.php"} instead. The
[navigation reference](/docs/admin/reference/navigation#adding-table-pages) shows how.

## Row links

A table can't show everything a user needs to see about a record. Link each row
to that record's detail page:

```php
use App\Models\ProductReview;
use Larasell\Admin\Tables\Table;

class ProductReviewTable extends Table
{
    // ...

    public function rowLink(ProductReview $productReview): ?string
    {
        return route('reviews.show', $productReview);
    }
}
```

Return `null` to leave a row unlinked:

```php
public function rowLink(ProductReview $productReview): ?string
{
    if (! $productReview->is_published) {
        return null;
    }

    return route('reviews.show', $productReview);
}
```

## Header actions

Some actions belong to the whole table rather than one row, like adding a new record.
Return them from the `headerActions` method and Larasell shows them above the table:

```php
use Larasell\Admin\Enums\Icon;
use Larasell\Admin\Tables\Actions\TableAction;
use Larasell\Admin\Tables\Table;

class ProductReviewTable extends Table
{
    // ...

    public function headerActions(): array
    {
        return [
            TableAction::make('Add review')
                ->route('reviews.create')
                ->icon(Icon::Add),
        ];
    }
}
```

A header action is a link. Use `route` to link to a named route, or `to` to link to any URL.
The `icon` method works the same as on [row actions](/docs/admin/reference/actions#icons).

Header actions are hidden while the table shows its [empty state](#empty-states). To offer
them in the empty state too, return them from the `actions` key:

```php
use Larasell\Admin\Tables\Table;

class ProductReviewTable extends Table
{
    // ...

    public function emptyState(): ?array
    {
        return [
            'title' => 'No reviews yet',
            'actions' => $this->headerActions(),
        ];
    }
}
```

## Table title

Each table has a title that Larasell displays. To customise the title, use the `title` method:

```php
use Larasell\Admin\Tables\Table;

class ProductReviewTable extends Table
{
    // ...

    public function title(): string
    {
        return 'My table';
    }
}
```

The title is optional. `Table`{href="https://raw.githubusercontent.com/Larasell-dev/admin/refs/heads/main/src/Tables/Table.php"} infers the
name based on the name of the class. `ProductReviewTable` turns into "Product review".

## Empty states

Larasell adds an empty state to each table.

Use the `emptyState`{href="https://raw.githubusercontent.com/Larasell-dev/admin/refs/heads/main/src/Tables/Table.php"} method to customise the empty state. It takes
a title, description and an icon:

```php
use Larasell\Admin\Enums\Icon;
use Larasell\Admin\Tables\Table;

class ProductReviewTable extends Table
{
    // ...

    public function emptyState(): ?array
    {
        return [
            'title' => 'No reviews yet',
            'description' => 'Reviews will show up here as soon as customers leave them.',
            'icon' => Icon::Star,
        ];
    }
}
```
