FilamentF
Filament11mo ago
jals65

Any way to get selected records on an bulkaction form?

Hi, I'm trying to get the selected records on a bulkaction to add the environments available on the multiselect options.

Any way to do that?

protected function setUp(): void
    {
        parent::setUp();
        $this->icon('heroicon-o-shield-check');
        $this->form(
            [
                Select::make('environments')
                    ->multiple()
                    ->options(function (Collection $records) {
                        $environments = [];
                        foreach ($records as $record) {
                            $projectEnvironments = Environment::where(EnvironmentInterface::PROJECT_ID, $record->name)->get();

                            foreach ($projectEnvironments as $projectEnvironment) {
                                $environments[$projectEnvironment] = "{$record->name} {$projectEnvironment->name}";
                            }
                        }

                        return $environments;
                    })
                    ->required()
            ]
        );
Solution
I can't get $livewire in the function parameter, but i can do $this->getLivewire()->getSelectedTableRecords() and it works
Was this page helpful?