Skip to content

Create a PowerGrid Table ​

Creating a PowerGrid Table ​

After base configuration, run php artisan powergrid:create. This walkthrough creates a ProductTable. For flags and stubs, see Create Table Command.

1. Component name ​

bash
$ php artisan powergrid:create
⚡ PowerGrid Table Generator

Enter a name for your new PowerGrid Table: ProductTable

CamelCase is recommended. The default suggestion is UserTable. If the component already exists, the generator asks before overwriting it.

2. Datasource ​

bash
 ┌ Select your preferred DataSource: ───────────────────────────┐
 │ › Eloquent Builder                                           │
 │   Query Builder                                              │
 │   Collection                                                 │
 └──────────────────────────────────────────────────────────────┘

See DataSource for when to use each type. This example uses Eloquent Builder.

3. Model (Eloquent) ​

Eloquent asks for a Model. Collection skips this step. Query Builder asks for a database table instead (see Query Builder).

bash
 ┌ Select a Model or enter its Fully qualified name. ───────────┐
 ├──────────────────────────────────────────────────────────────┤
 │› App\Models\Product                                          │
 │  App\Models\FooBar                                           │
 │  App\Models\FoorBarBaz                                       │
 └──────────────────────────────────────────────────────────────┘

By default, PowerGrid lists Models under app/Models. Change that in Customizing the Creation Process.

4. Auto-import fields ​

bash
 ┌ Auto-import Data Source fields from [Product] Model? ────────┐
 │ ● Yes / ○ No                                                 │
 └──────────────────────────────────────────────────────────────┘

Answer No to skip import. The default stub still includes sample id / name / created_at columns plus Action.

If the database has no tables, this prompt is skipped.

5. Column source (Eloquent only) ​

Eloquent then asks where the fields should come from. Query Builder does not ask this — it always reads the selected table.

bash
 ┌ Where should the fields come from? ──────────────────────────┐
 │ › $fillable in [Product] Model                               │
 │   Columns in [products] DB table                             │
 └──────────────────────────────────────────────────────────────┘

6. Preview and confirm ​

bash
👀 Preview of the fields from $fillable in [Product]:

  Field      Type      Generated as
  id         integer   Plain column
  name       string    Sortable, searchable column + text filter
  price      other     Sortable, searchable column
  in_stock   boolean   Toggleable column + boolean filter
  created_at datetime  Sortable column, formatted d/m/Y H:i:s + datetime filter

 ┌ Generate the component with these fields? ───────────────────┐
 │ ● Yes / ○ No                                                 │
 └──────────────────────────────────────────────────────────────┘

The Type column is the bucket the database type maps to:

TypeDatabase typesGenerated as
stringvarchar, char, text variants, uuid, enumsortable() + searchable() + Filter::inputText()
integerint variants, serialPlain column, no filter
booleanbool, bit, tinyint(1)toggleable() + Filter::boolean()
datedatesortable(), formatted d/m/Y + Filter::datepicker()
datetimedatetime, timestamp variantssortable(), formatted d/m/Y H:i:s + Filter::datetimepicker()
otheranything else (decimal, json, …)sortable() + searchable(), no filter

With $fillable, fields are ordered primary key, $fillable, then created_at. The model's $hidden attributes are always skipped, and the table-schema source also skips sensitive columns (password, remember_token, api_token, and similar). If the source has no fields, only the Action column is generated.

Answer No to discard the preview. The generator then uses the default stub (sample id / name / created_at plus Action), same as declining auto-import.

7. Done ​

bash
⚡ ProductTable was successfully created at [app/Livewire/ProductTable.php].

💡 include the ProductTable component using the tag: <livewire:product-table/>

🎉 Everything is in place

Next: Render a PowerGrid Table.

Query Builder ​

Query Builder asks for a table instead of a Model, then the same auto-import prompt. It does not ask column source.

bash
 ┌ Select your preferred DataSource: ───────────────────────────┐
 │   Eloquent Builder                                           │
 │ › Query Builder                                              │
 │   Collection                                                 │
 └──────────────────────────────────────────────────────────────┘

 ┌ Enter or Select a DB Table ──────────────────────────────────┐
 │ products                                                     │
 └──────────────────────────────────────────────────────────────┘

 ┌ Auto-import Data Source fields from [products] table? ───────┐
 │ ● Yes / ○ No                                                 │
 └──────────────────────────────────────────────────────────────┘

Collection skips Model, table, auto-import, and preview.

Created By Luan Freitas and @DanSysAnalyst