How to get current record on Table action using a custom form field

Hi, I have a Resource with a Table action using a custom field. I need pass data to the view for this action - all works well for user details but how do I pass the current record’s ID? I’ve tried lots of approaches but it never passes the data
// Resource class action $table actions
Tables\Actions\Action::make('Publish')
->form([
BraintreePayment::make('Billing details')
->viewData([
'first_name' => auth()->user()->first_name,
...
'payment' => [
'type' => 'publish',
// 'record_id' => fn (Model $record) => $record,
'record_id' => fn ($form) => $form->getRecord(), // $record->id,
]
])
])
// Resource class action $table actions
Tables\Actions\Action::make('Publish')
->form([
BraintreePayment::make('Billing details')
->viewData([
'first_name' => auth()->user()->first_name,
...
'payment' => [
'type' => 'publish',
// 'record_id' => fn (Model $record) => $record,
'record_id' => fn ($form) => $form->getRecord(), // $record->id,
]
])
])
I know I can get the record in my BraintreePayment Blade using recordId: '{{ $getRecord()->id }}' but this doesn’t work for me as I want to pass in an object of data to make the component describing the type of payment being made more reusable for different situations.
1 Reply
Ric Le Poidevin
Ric Le PoidevinOP12mo ago
Thinking about this a but more, the other option would be to access the record in the Field’s class class BraintreePayment extends Field but calling $this->getRecord() errors: Typed property Filament\Forms\Components\Component::$container must not be accessed before initialization
Want results from more Discord servers?
Add your server