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.
})
4 Replies
Just use
$records
.
->afterStateUpdated(function($state) => dd($records))
Thank you .I tried but i get the error
Undefined variable $records
Undefined variable $records
You need a
use
statement to access outside vars in your functionThank you.It worked.