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()
]
);
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
Jump to solution
3 Replies
christmex
christmex2w ago
try this
->action(function($livewire){
dd($livewire->getSelectedRecords());
})
->action(function($livewire){
dd($livewire->getSelectedRecords());
})
if im not wrong
Solution
jals65
jals652w ago
I can't get $livewire in the function parameter, but i can do $this->getLivewire()->getSelectedTableRecords() and it works
jals65
jals65OP2w ago
thanks

Did you find this page helpful?