Generating Tables via Artisan
Zonvoir Table includes an Artisan command for quickly generating table classes.
Generate a table
Section titled “Generate a table”Run the make:zon-table command with the name of your table:
php artisan make:zon-table UsersTableThis creates a new table class inside:
app/Tables/UsersTable.phpGenerate a table for a model
Section titled “Generate a table for a model”You can associate the table with an Eloquent model using the --model option:
php artisan make:zon-table UsersTable --model=UserThis generates a table class with the model already configured:
<?php
namespace App\Tables;
use App\Models\User;use Zonvoir\InertiaTable\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 [ // ]; }}Table name
Section titled “Table name”The table name should use PascalCase and typically end with Table.
For example:
php artisan make:zon-table EmployeesTable --model=Employeephp artisan make:zon-table OrdersTable --model=Orderphp artisan make:zon-table CustomersTable --model=CustomerModel option
Section titled “Model option”The --model option accepts the model class name:
php artisan make:zon-table UsersTable --model=UserYou can also provide a namespaced model:
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;Custom directory and paths
Section titled “Custom directory and paths”You have multiple ways to generate tables in custom directories and namespaces.
1. Direct path in the table name
Section titled “1. Direct path in the table name”You can pass the full relative path directly in the command (using either forward slashes or backslashes):
php artisan make:zon-table app/Http/Controllers/UserTableThis generates the file directly at that location (e.g. app/Http/Controllers/UserTable.php) with the corresponding namespace (e.g. app\Http\Controllers\).
2. Using the --path option
Section titled “2. Using the --path option”You can also specify the target directory with the --path option:
php artisan make:zon-table UsersTable --path="app/DataTables"You can omit the leading app/ if you prefer:
php artisan make:zon-table UsersTable --path="DataTables"You can combine --path with --model:
php artisan make:zon-table UsersTable --path="app/DataTables" --model=User3. Configuring the default directory in config
Section titled “3. Configuring the default directory in config”To change the default directory for all future make:zon-table commands, publish the configuration file and set tables_path in config/zonvoir-table.php:
'tables_path' => 'app/DataTables',The table class namespace is automatically derived from this path (e.g. App\DataTables). Command-line options like --path or direct argument paths always take precedence over the configuration.
Adding columns
Section titled “Adding columns”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.
What’s next?
Section titled “What’s next?”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.