Workflow
Validation

This example illustrates the use of Validation Rules in your table.
Click and edit the name. The component only accepts names between 2 and 10 characters.

Id
NAME
EMAIL
Active
1
luanfreitasdev@fakemail.com
2
dansysanalyst@fakemail.com
3
claudio@fakemail.com
4
vitao@fakemail.com
5
tiojobs@fakemail.com
Disclaimer: Table data is randomly generated for illustrative purposes only. The information here is not a reflection of the actual market and does not constitute business, financial, or medical advice.
open in GitHub
<?php
 
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Footer;
use PowerComponents\LivewirePowerGrid\Header;
use PowerComponents\LivewirePowerGrid\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
 
final class ValidationTable extends PowerGridComponent
{
public array $name;
 
public bool $showErrorBag = true;
 
public string $tableName = 'validationTable';
 
protected array $rules = [
'name.*' => ['required', 'min:2', 'max:10'],
];
 
public function setUp(): array
{
return [
Header::make()
->showSearchInput(),
 
Footer::make()
->showPerPage()
->showRecordCount(),
];
}
 
public function onUpdatedEditable(string|int $id, string $field, string $value): void
{
$this->validate();
}
 
public function onUpdatedToggleable(string|int $id, string $field, string $value): void
{
$this->skipRender();
}
 
public function datasource(): ?Builder
{
return User::query();
}
 
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('active')
->add('name')
->add('email');
}
 
public function columns(): array
{
return [
Column::make('Id', 'id'),
 
Column::make('NAME', 'name')
->sortable()
->editOnClick(true)
->searchable(),
 
Column::make('EMAIL', 'email')
->sortable()
->searchable(),
 
Column::make('Active', 'active')
->toggleable(),
];
}
}

Here you can find all relevant packages installed on this demo.

Name
Version
Description
laravel/framework
v10
The Laravel Framework.
openspout/openspout
v4.23.0
PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
power-components/livewire-powergrid
5.x-dev
PowerGrid generates Advanced Datatables using Laravel Livewire.