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\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 [ // ]; }}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;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.