Setting a field value from an action

This is my action: Actions\Action::make('gespreksverslag_herschrijven') ->label('Gespreksverslag herschrijven') ->icon('heroicon-o-pencil') ->action(function(){

$originalText = $this->data['conversation_report_original']; $service = new RewriteTextWithGPTService(); $rewrittenText = $service->handle(static::$prompt, $originalText); $this->form->fill([ 'conversation_report_gpt' => $rewrittenText, ], true);
}),
Im trying to fill the field 'conversation_report_gpt' but it's not filling anything. I also tried other things such as $this->data['conversation_report_gpt'] = $something and $set() but none of them works for me. This action resides in a Create page of resource
1 Reply
Patrick
PatrickOP9mo ago
Got it working. No idea if it's the right way to do it, but here is a solution:
Actions\Action::make('gespreksverslag_herschrijven')
->label('Gespreksverslag herschrijven')
->icon('heroicon-o-pencil')
->action(function(){


$originalText = $this->data['conversation_report_original'];
$service = new RewriteTextWithGPTService();
$rewrittenText = $service->handle(static::$prompt, $originalText);

$currentState = $this->data;
$newState = array_merge(['conversation_report_gpt' => $rewrittenText], $currentState);

$this->form->fill($newState, true, false);

}),
Actions\Action::make('gespreksverslag_herschrijven')
->label('Gespreksverslag herschrijven')
->icon('heroicon-o-pencil')
->action(function(){


$originalText = $this->data['conversation_report_original'];
$service = new RewriteTextWithGPTService();
$rewrittenText = $service->handle(static::$prompt, $originalText);

$currentState = $this->data;
$newState = array_merge(['conversation_report_gpt' => $rewrittenText], $currentState);

$this->form->fill($newState, true, false);

}),
Want results from more Discord servers?
Add your server