mugiwara
mugiwara
FFilament
Created by mugiwara on 9/25/2023 in #❓┊help
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();
}
}
5 replies
FFilament
Created by mugiwara on 9/1/2023 in #❓┊help
datepicker state update
Forms\Components\DatePicker::make('plan_started')
->afterStateUpdated(function (Closure $set, Closure $get, $state) {
$state = Carbon::parse($state);
$set('plan_expires', $get('plan_term') == 'year' ? $state->addYear() : $state->addMonth());
})->format('Y-m-d')
->displayFormat('d-m-Y'),
Forms\Components\DatePicker::make('plan_expires')
->disabled()
->format('Y-m-d')
->displayFormat('d-m-Y')
Forms\Components\DatePicker::make('plan_started')
->afterStateUpdated(function (Closure $set, Closure $get, $state) {
$state = Carbon::parse($state);
$set('plan_expires', $get('plan_term') == 'year' ? $state->addYear() : $state->addMonth());
})->format('Y-m-d')
->displayFormat('d-m-Y'),
Forms\Components\DatePicker::make('plan_expires')
->disabled()
->format('Y-m-d')
->displayFormat('d-m-Y')
i want to select a date in 'plan_started' datepicker and using that date for 'plan_expires'. in filament v2 i used this code and works like i wanted. in v3 it is not works.i look at changes and see the 'closure' was changed to 'Set' and 'Get' but still i could not succeed. how should i change the codes ? thanks
17 replies