Skip to content

Artisan Command

Inertia Table ships with a make:table generator to scaffold new table classes.

Basic Usage

bash
php artisan make:table ServerTable

This creates app/Tables/ServerTable.php:

php
<?php

namespace App\Tables;

use Forjed\InertiaTable\Table;
use Forjed\InertiaTable\Column;

class ServerTable extends Table
{
    protected function columns(): array
    {
        return [
            // TODO: Define your columns here
        ];
    }

    protected function searchable(): array
    {
        return [];
    }
}

The app/Tables directory is created automatically if it doesn't exist.

Scaffolding from a Model

Pass --model to generate columns from the model's $fillable array:

bash
php artisan make:table ServerTable --model=Server

The model is resolved from App\Models by default. You can also pass a fully qualified class name:

bash
php artisan make:table ServerTable --model=App\\Models\\Server

If the model has protected $fillable = ['name', 'ip', 'status'], the generated class includes:

php
<?php

namespace App\Tables;

use Forjed\InertiaTable\Table;
use Forjed\InertiaTable\Column;
use App\Models\Server;

class ServerTable extends Table
{
    protected function columns(): array
    {
        return [
            Column::make('name', 'Name'),
            Column::make('ip', 'Ip'),
            Column::make('status', 'Status'),
        ];
    }

    protected function searchable(): array
    {
        return [];
    }
}

From here you would typically swap Column::make() for typed columns, add ->sortable(), configure search fields, and add hidden data columns:

php
use Forjed\InertiaTable\Columns\{LinkColumn, CopyableColumn, EnumColumn, ActionsColumn};

protected function columns(): array
{
    return [
        LinkColumn::make('name', 'Name')->route('servers.show', ['server' => ':id'])->sortable(),
        CopyableColumn::make('ip', 'IP Address')->sortable(),
        EnumColumn::make('status', 'Status')->sortable(),
        ActionsColumn::make(),
        Column::data('id'),
    ];
}

protected function searchable(): array
{
    return ['name', 'ip'];
}

Arguments & Options

Argument / OptionDescription
nameThe class name for the table (e.g. ServerTable)
--model=Eloquent model to scaffold columns from (e.g. Server or App\Models\Server)

Notes

  • If a table class with the same name already exists, the command will fail with an error rather than overwriting it.
  • If --model is provided but the model has no $fillable array (or the class can't be found), the columns will fall back to a // TODO placeholder.
  • The generated class uses Column::make() for all fields. You'll want to replace these with typed column classes for a better developer experience.