$container must not be accessed before initialization from within Action

I have the following header Action on an EditOrder resource page.
Actions\Action::make('process_return')
->form(function(Get $get, $record) {
$fields = [];

foreach ($record->items as $orderItem) {
$fields[] = Group::make([
Placeholder::make($orderItem->id.'product_title')
->label('Product')
->content(function() use ($orderItem) {
return $orderItem->product_title . ($orderItem->product_option_title ? ' - ' . $orderItem->product_option_title : '');
}),
TextInput::make($orderItem->id.'.quantity_to_return')
->label('Quantity to return/refund.')
->numeric()
->maxValue($orderItem->quantity)
->suffix('/ ' . $orderItem->quantity)
->live(),
Placeholder::make($orderItem->id.'return_value')
->label('Return value')
->content(function() use ($get, $orderItem) {
return $get($orderItem->id.'.quantity_to_return');
}),
])
->columns(4);
}

return $fields;
})
->action(function (array $data) {
dd($data);
}),
Actions\Action::make('process_return')
->form(function(Get $get, $record) {
$fields = [];

foreach ($record->items as $orderItem) {
$fields[] = Group::make([
Placeholder::make($orderItem->id.'product_title')
->label('Product')
->content(function() use ($orderItem) {
return $orderItem->product_title . ($orderItem->product_option_title ? ' - ' . $orderItem->product_option_title : '');
}),
TextInput::make($orderItem->id.'.quantity_to_return')
->label('Quantity to return/refund.')
->numeric()
->maxValue($orderItem->quantity)
->suffix('/ ' . $orderItem->quantity)
->live(),
Placeholder::make($orderItem->id.'return_value')
->label('Return value')
->content(function() use ($get, $orderItem) {
return $get($orderItem->id.'.quantity_to_return');
}),
])
->columns(4);
}

return $fields;
})
->action(function (array $data) {
dd($data);
}),
I am attempting to use Get $get($orderItem->id.'.quantity_to_return') to retrieve the quantity of items that are being returned so that I can show a preview of the $ amount that will be refunded. However, I am getting "$container must not be accessed before initialization" when attempting to call $get(). Is $get() not possible within a header Action? Any other way I can achieve this? Thanks
1 Reply
LeandroFerreira
you can use $get in header actions. Does it work?
Actions\Action::make('customAction')
->form([
TextInput::make('name')
->default(fake()->name)
->live(debounce: 800),
Placeholder::make('output')
->content(fn(Get $get) => $get('name'))
]),
Actions\Action::make('customAction')
->form([
TextInput::make('name')
->default(fake()->name)
->live(debounce: 800),
Placeholder::make('output')
->content(fn(Get $get) => $get('name'))
]),
Want results from more Discord servers?
Add your server