Enum
ID
Dish
Diet
|
ID
|
Dish
|
Diet
|
---|---|---|---|
|
|
|
|
|
1
|
Arkansas Possum Pie
|
π½οΈ All diets
|
|
2
|
Albacore Tuna Melt
|
π± Suitable for Vegans
|
|
3
|
Π±ΠΎΡΡ
|
π± Suitable for Vegans
|
|
4
|
Bacalhau com natas
|
π½οΈ All diets
|
|
5
|
Baba Ghanoush
|
π½οΈ All diets
|
|
6
|
Bacon Cheeseburger
|
π₯ Suitable for Celiacs
|
|
7
|
Baked potato
|
π± Suitable for Vegans
|
|
8
|
Baklava
|
π± Suitable for Vegans
|
|
9
|
Bangers and mash
|
π± Suitable for Vegans
|
|
10
|
Black Pudding
|
π± Suitable for Vegans
|
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\EnumTable;
use App\Enums\Diet;
use App\Models\Dish;
use Illuminate\Database\Eloquent\Builder;
use PowerComponents\LivewirePowerGrid\Column;
use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Facades\PowerGrid;
use PowerComponents\LivewirePowerGrid\PowerGridComponent;
use PowerComponents\LivewirePowerGrid\PowerGridFields;
class EnumTable extends PowerGridComponent
{
public string $tableName = 'enum-table';
public bool $filtersOutside = false;
public string $sortField = 'dishes.id';
public bool $ableToLoad = false;
public function setUp(): array
{
$this->showCheckBox();
return [
PowerGrid::header()
->showToggleColumns(),
PowerGrid::footer()
->showPerPage()
->showRecordCount(),
];
}
public function datasource(): ?Builder
{
return Dish::query();
}
public function relationSearch(): array
{
return [
'category' => [
'name',
],
];
}
public function fields(): PowerGridFields
{
return PowerGrid::fields()
->add('id')
->add('dish_name', fn ($dish) => $dish->name)
->add('diet', fn ($dish) => \App\Enums\Diet::from($dish->diet)->labels());
}
public function columns(): array
{
return [
Column::add()
->title('ID')
->field('id', 'dishes.id')
->searchable()
->sortable(),
Column::add()
->title('Dish')
->field('dish_name', 'dishes.name')
->searchable()
->contentClasses('!whitespace-normal')
->placeholder('placeholder')
->sortable(),
Column::add()
->field('diet', 'dishes.diet')
->searchable()
->title('Diet'),
];
}
public function filters(): array
{
return [
Filter::enumSelect('diet', 'dishes.diet')
->dataSource(Diet::cases())
->optionLabel('dishes.diet'),
];
}
}