F
Filament7mo ago
Jonas

Defining record in Table EditAction not working

Hi I am having an issue with the table EditAction when using another model than what the table record has. My setup has a task model and then a taskAnswer model (witch belongs to the task). My issue is that even though i define EditRecord to edit the taskanswer, it tries to update the task instead. (I have removed alot of irrelevant code in below snippets) Edit Action
public static function editAnswerAction()
{
return Tables\Actions\EditAction::make()
->model(TaskAnswer::class)
->record(function (Task $record): TaskAnswer {
return $record->answer;
})
->mutateFormDataUsing(function (array $data, Task $ownerRecord): array {
$data["user_id"] = auth()->id();
return static::resolveDataManipulation($ownerRecord, $data);
})
->steps(function(Task $record) {
return static::resolveModalSteps($record);
});
}
public static function editAnswerAction()
{
return Tables\Actions\EditAction::make()
->model(TaskAnswer::class)
->record(function (Task $record): TaskAnswer {
return $record->answer;
})
->mutateFormDataUsing(function (array $data, Task $ownerRecord): array {
$data["user_id"] = auth()->id();
return static::resolveDataManipulation($ownerRecord, $data);
})
->steps(function(Task $record) {
return static::resolveModalSteps($record);
});
}
This tries to update the task, and not the task answer - even though i have defined both model and record. Im kinda stuck here.. I have a similiar approach to create record, and that works fine.
public static function createAnswerAction()
{
return Tables\Actions\CreateAction::make()
->model(TaskAnswer::class)
->mutateFormDataUsing(function (array $data, Task $ownerRecord): array {
$data["task_id"] = $ownerRecord->id;
$data["user_id"] = auth()->id();
return static::resolveDataManipulation($ownerRecord, $data);
})
->steps(function(Task $record) {
return static::resolveModalSteps($record);
});
}
public static function createAnswerAction()
{
return Tables\Actions\CreateAction::make()
->model(TaskAnswer::class)
->mutateFormDataUsing(function (array $data, Task $ownerRecord): array {
$data["task_id"] = $ownerRecord->id;
$data["user_id"] = auth()->id();
return static::resolveDataManipulation($ownerRecord, $data);
})
->steps(function(Task $record) {
return static::resolveModalSteps($record);
});
}
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server