Workflow
Persist

This example enables the Persist feature.

(This Table is a variation of the "Dish" example.)

ID
Dish
Diet
Category
Price
Calories
Production date
In Stock
Action
ID
Dish
Diet
Category
Price
Calories
Production date
In Stock
Action
1
Arkansas Possum Pie
🥜 Suitable for Celiacs
Soup
434 kcal
04/10/2024
2
Albacore Tuna Melt
🍽️ All diets
Pasta
828 kcal
22/09/2024
3
борщ
🍽️ All diets
391 kcal
09/10/2024
4
Bacalhau com natas
🥜 Suitable for Celiacs
Dessert
573 kcal
17/09/2024
5
Baba Ghanoush
🥜 Suitable for Celiacs
Soup
735 kcal
03/10/2024
6
Bacon Cheeseburger
🍽️ All diets
Soup
806 kcal
03/10/2024
7
Baked potato
🥜 Suitable for Celiacs
534 kcal
06/10/2024
8
Baklava
🍽️ All diets
750 kcal
11/10/2024
9
Bangers and mash
🌱 Suitable for Vegans
203 kcal
30/09/2024
10
Black Pudding
🥜 Suitable for Celiacs
330 kcal
21/09/2024
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.
<?php
 
namespace App\Livewire\Examples\PersistTable;
 
use App\Enums\Diet;
use App\Livewire\Examples\DemoDishTable\DemoDishTable;
use App\Models\Category;
use App\Models\Chef;
use Illuminate\Database\Eloquent\Builder;
use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
 
final class PersistTable extends DemoDishTable
{
public string $tableName = 'persist-table';
 
public function setUp(): array
{
$this->persist(['columns', 'filters'], prefix: auth()->id ?? '');
 
return [
PowerGrid::header()
->showToggleColumns()
->withoutLoading()
->showSearchInput(),
 
PowerGrid::footer()
->showPerPage()
->showRecordCount(),
];
}
 
public function header(): array
{
return [];
}
 
public function filters(): array
{
return [
Filter::inputText('dish_name', 'dishes.name'),
 
Filter::inputText('name')
->placeholder('Test')
->operators(['contains']),
 
Filter::boolean('in_stock', 'in_stock')
->label('In stock', 'Out of stock'),
 
Filter::enumSelect('diet', 'dishes.diet')
->dataSource(Diet::cases())
->optionLabel('dishes.diet'),
 
Filter::select('category_name', 'category_id')
->dataSource(Category::all())
->optionLabel('name')
->optionValue('id'),
 
Filter::select('chef_name', 'chef_id')
->depends(['category_id'])
->dataSource(
fn ($depends) => Chef::query()
->when(
isset($depends['category_id']),
fn (Builder $query) => $query->whereRelation(
'categories',
fn (Builder $builder) => $builder->where('id', $depends['category_id'])
)
)
->get()
)
->optionLabel('name')
->optionValue('id'),
 
Filter::number('price_BRL', 'price'),
 
Filter::datetimepicker('created_at_formatted', 'created_at')
->params([
'timezone' => 'America/Sao_Paulo',
]),
];
}
}
Code highlighting provided by Torchlight.dev