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
🍽️ All diets
178 kcal
28/11/2024
2
Albacore Tuna Melt
🌱 Suitable for Vegans
855 kcal
10/12/2024
3
борщ
🌱 Suitable for Vegans
184 kcal
18/12/2024
4
Bacalhau com natas
🍽️ All diets
Garnish
444 kcal
01/12/2024
5
Baba Ghanoush
🍽️ All diets
Soup
118 kcal
22/11/2024
6
Bacon Cheeseburger
🥜 Suitable for Celiacs
233 kcal
18/12/2024
7
Baked potato
🌱 Suitable for Vegans
843 kcal
08/12/2024
8
Baklava
🌱 Suitable for Vegans
731 kcal
22/11/2024
9
Bangers and mash
🌱 Suitable for Vegans
734 kcal
25/11/2024
10
Black Pudding
🌱 Suitable for Vegans
360 kcal
24/11/2024
Showing 1 to 10 of 192 Results
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',
                ]),
        ];
    }
}