<?php
namespace App\Filament\Resources\OperatorResource\Pages;
use App\Filament\Resources\OperatorResource;
use App\Models\Attribute;
use App\Models\Resort;
use Filament\Actions;
use Filament\Forms\Components\CheckboxList;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Form;
use Filament\Resources\Pages\EditRecord;
class EditOperator extends EditRecord
{
protected static string $resource = OperatorResource::class;
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
public function form(Form $form): Form
{
$attributes = Attribute::whereAllowsModel(Resort::class)->get();
$data = $attributes->groupBy('group')->map(function ($item) {
return $item->pluck('name', 'id')->toArray();
});
return $form
->schema([
Section::make('Suche')
->schema([
Select::make('query')
->label('Gruppe')
->options(Attribute::whereAllowsModel(Resort::class)->select('group')->distinct()->get()->map(fn ($value) => $value['group']))
->searchable()
]),
Section::make('Attribute')
->schema(
$data->map(function ($attributes, $group) {
return CheckboxList::make($group)
->options($attributes)
->visible();
}
)->toArray()
)
->columns(3)
]);
}
}