Skip to content
Zonvoir Table LogoZonvoir Table

Generating Tables via Artisan

Zonvoir Table includes an Artisan command for quickly generating table classes.

Run the make:zon-table command with the name of your table:

Terminal window
php artisan make:zon-table UsersTable

This creates a new table class inside:

app/Tables/UsersTable.php

You can associate the table with an Eloquent model using the --model option:

Terminal window
php artisan make:zon-table UsersTable --model=User

This generates a table class with the model already configured:

<?php
namespace App\Tables;
use App\Models\User;
use Zonvoir\ZonvoirTable\Table;
class UsersTable extends Table
{
protected ?string $resource = User::class;
public function columns(): array
{
return [
//
];
}
public function actions(): array
{
return [
//
];
}
public function exports(): array
{
return [
//
];
}
}

The table name should use PascalCase and typically end with Table.

For example:

Terminal window
php artisan make:zon-table EmployeesTable --model=Employee
php artisan make:zon-table OrdersTable --model=Order
php artisan make:zon-table CustomersTable --model=Customer

The --model option accepts the model class name:

Terminal window
php artisan make:zon-table UsersTable --model=User

You can also provide a namespaced model:

Terminal window
php artisan make:zon-table UsersTable --model="App\Models\User"

The generated $resource property tells Zonvoir Table which Eloquent model the table should query.

protected ?string $resource = User::class;

After generating the table, define the columns you want to display inside columns():

public function columns(): array
{
return [
TextColumn::make('id', 'ID'),
TextColumn::make('name', 'Name'),
TextColumn::make('email', 'Email'),
];
}

You can then continue configuring sorting, column visibility, actions, pagination, exports, and other table features as needed.

Once your table has been generated, you can:

  • Define your table columns
  • Configure row and bulk actions
  • Configure pagination and sorting
  • Add exports
  • Customize the table appearance and behavior

Continue to the Columns documentation to start building your table.