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 โ
$ php artisan powergrid:create
โก PowerGrid Table Generator
Enter a name for your new PowerGrid Table: ProductTableCamelCase is recommended. The default suggestion is UserTable. If the component already exists, the generator asks before overwriting it.
2. Datasource โ
โ 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).
โ 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 โ
โ 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.
โ Where should the fields come from? โโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โบ $fillable in [Product] Model โ
โ Columns in [products] DB table โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ6. Preview and confirm โ
๐ 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:
| Type | Database types | Generated as |
|---|---|---|
string | varchar, char, text variants, uuid, enum | sortable() + searchable() + Filter::inputText() |
integer | int variants, serial | Plain column, no filter |
boolean | bool, bit, tinyint(1) | toggleable() + Filter::boolean() |
date | date | sortable(), formatted d/m/Y + Filter::datepicker() |
datetime | datetime, timestamp variants | sortable(), formatted d/m/Y H:i:s + Filter::datetimepicker() |
other | anything 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 โ
โก 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.
โ 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.
