Access BulkAction $record inside a form field closure

BulkAction::make('Send Invoice')->icon('heroicon-o-template')->deselectRecordsAfterCompletion()->action(function (Collection $records) {
dd($records); //the records populate as expected
})->form(
function (Collection $records) {
dd($records) ; //gives the selected records
return [
Card::make()->schema([
Radio::make('invoice_type')->options(function () {
$utils = [];
$utilities = Utility::pluck('utility_name');

if ($utilities->isNotEmpty()) {
foreach ($utilities as $key => $value) {
$utils[$value] = $value;
}
return array_merge($utils, ['Standard' => 'Standard', 'Rent' => 'Rent']);
} else {
return [
'Standard' => 'Standard',
'Rent' => 'Rent'
];
}
})->inline()->required()->reactive()->afterStateUpdated(function($state,Collection $records) {
dd($records); //ERROR:: EMPTY COLLECTION
//I want to access the $records here.
})
BulkAction::make('Send Invoice')->icon('heroicon-o-template')->deselectRecordsAfterCompletion()->action(function (Collection $records) {
dd($records); //the records populate as expected
})->form(
function (Collection $records) {
dd($records) ; //gives the selected records
return [
Card::make()->schema([
Radio::make('invoice_type')->options(function () {
$utils = [];
$utilities = Utility::pluck('utility_name');

if ($utilities->isNotEmpty()) {
foreach ($utilities as $key => $value) {
$utils[$value] = $value;
}
return array_merge($utils, ['Standard' => 'Standard', 'Rent' => 'Rent']);
} else {
return [
'Standard' => 'Standard',
'Rent' => 'Rent'
];
}
})->inline()->required()->reactive()->afterStateUpdated(function($state,Collection $records) {
dd($records); //ERROR:: EMPTY COLLECTION
//I want to access the $records here.
})
Any help.I want to access the $records inside the afterStateUpdated() closure.
4 Replies
Dennis Koch
Dennis Koch2y ago
Just use $records. ->afterStateUpdated(function($state) => dd($records))
lodeki
lodekiOP2y ago
Thank you .I tried but i get the error
Undefined variable $records
Undefined variable $records
Dennis Koch
Dennis Koch2y ago
You need a use statement to access outside vars in your function
lodeki
lodekiOP2y ago
Thank you.It worked.
Want results from more Discord servers?
Add your server