I need to access $record on Table Action form

I have the following. In relation to the invoiceReadyValue form field. this is a value already stored on the record but I want the ability to edit this field and then save it. I may have a few forms for different actions on the table row. I cannot work out how to prefil the value into the form entry though, its blank but there is a value stored. Any ideas? Thanks all.
->actions([
ActionGroup::make([
Action::make('Toggle Supplier Order')
->requiresConfirmation()
->action(fn (docket $record) => $record->update(['docProgSupplierOrder'=> !$record->docProgSupplierOrder ])),
Action::make('Submit For Invoicing')
->accessSelectedRecords()
->form([
TextInput::make('invoiceReadyValue')->required(),
])
->action(function (array $data, docket $record): void {
$record->invoiceReadyValue = $data['invoiceReadyValue'];
$record->save();
Notification::make()
->title('Invoice Submitted')
->success()
->send();
})
])
->actions([
ActionGroup::make([
Action::make('Toggle Supplier Order')
->requiresConfirmation()
->action(fn (docket $record) => $record->update(['docProgSupplierOrder'=> !$record->docProgSupplierOrder ])),
Action::make('Submit For Invoicing')
->accessSelectedRecords()
->form([
TextInput::make('invoiceReadyValue')->required(),
])
->action(function (array $data, docket $record): void {
$record->invoiceReadyValue = $data['invoiceReadyValue'];
$record->save();
Notification::make()
->title('Invoice Submitted')
->success()
->send();
})
])
10 Replies
LeandroFerreira
LeandroFerreira11mo ago
->mountUsing(fn (Form $form, $record) => $form->fill($record->attributesToArray()))
->mountUsing(fn (Form $form, $record) => $form->fill($record->attributesToArray()))
David | Fortune Validator
thank you so much. That worked. May I ask where in the docs you found that?
David | Fortune Validator
thank you. Does this stop relationships from working correctly? I need a select dropdown that is part of a relationship between the Docket and another model
LeandroFerreira
LeandroFerreira11mo ago
this should work. What is the issue?
David | Fortune Validator
Data wasnt pulling into the component for the relationship. It may be user error though so I'll lkeep trying. I dont suppose you know how to use a multi level relationship on a Select? e.g Docket has an Estimate which has a Product Type. Relations are setup in models okay I can pull in lets say 'estimate','id' okay but how would I go a level deeper?
LeandroFerreira
LeandroFerreira11mo ago
What code are you trying to do?
David | Fortune Validator
Not by my pc at the moment. I think though perhaps I need a new relationship on my Docket to pass through the Estimste and onto ProductType. #p.s fairly new to relationships embarrassingly Okay so I’m a little stumped. I have the following Docket Model ( contains an estimate_id) Estimate Model ( contains an product_id) Product Model On my Docket model based form. I want to use a Select component to access the product list and assigned product to the estimate. So as you can see it’s two levels deep. From the select relationship documentation I can only see the ability to go one level deep. Such as access estimates_id’s from Docket. As I’m typing this however. I’m seriously wondering if the product should be linked to the docket once a docket is created anyway.
awcodes
awcodes11mo ago
You might be able to do it with a HasManyThrough relationship.
David | Fortune Validator
Thought about that but it’s all one belongs to one. I’ve moved product id to the docket know. Which to be honest it should have been. Thank you
Want results from more Discord servers?
Add your server