get form data from action

hi, i want to learn is there a change about get data in action form. In v2 i use this code in my resource's view page and i can get data to 'apiTest' function but now in v3 i get the error Unable to resolve dependency [Parameter #0 [ <required> array $data ]] in class App\Filament\Resources\CompanyResource\Pages\ViewCompany.
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
Actions\Action::make('api_test')->form([
TextInput::make('test')
])->action('apiTest'),
];
}


public function apiTest(array $data): void
{
try {

$response = $this->apiService->_post('api-test', $data, true);

Notification::make()
->title('Saved successfully')
->body($response['message'])
->success()
->seconds(4)
->send();

} catch (\Throwable $th) {
Notification::make()->title('Error Code ' . $th->getCode())
->danger()
->body($th->getMessage())
->seconds(20)
->send();
}
}
protected function getHeaderActions(): array
{
return [
Actions\EditAction::make(),
Actions\Action::make('api_test')->form([
TextInput::make('test')
])->action('apiTest'),
];
}


public function apiTest(array $data): void
{
try {

$response = $this->apiService->_post('api-test', $data, true);

Notification::make()
->title('Saved successfully')
->body($response['message'])
->success()
->seconds(4)
->send();

} catch (\Throwable $th) {
Notification::make()->title('Error Code ' . $th->getCode())
->danger()
->body($th->getMessage())
->seconds(20)
->send();
}
}
Solution:
I think you need to get the data in the action() callback, and pass it to your method: ```php ->action(function ($livewire, $data) { $livewire->apiTest($data); })...
Jump to solution
2 Replies
Solution
Patrick Boivin
Patrick Boivin15mo ago
I think you need to get the data in the action() callback, and pass it to your method:
->action(function ($livewire, $data) {
$livewire->apiTest($data);
})
->action(function ($livewire, $data) {
$livewire->apiTest($data);
})
mugiwara
mugiwaraOP15mo ago
thanks, that solved my problem
Want results from more Discord servers?
Add your server