F
Filament17mo ago
dyo

get form data in after() method

How can i get form data in after() in CreateAction class? i'm using modal form.. i have a code something like this
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data) {
unset($data['setoran_id']);

return $data;
})->after(function (array $data) {
// I want to use $data['setoran_id'] in here..
}),
Tables\Actions\CreateAction::make()
->mutateFormDataUsing(function (array $data) {
unset($data['setoran_id']);

return $data;
})->after(function (array $data) {
// I want to use $data['setoran_id'] in here..
}),
Solution:
got it, i'm using $livewire->mountedTableActionData to get the forms value in after().. thanks for @awcodes and @Leandro Ferreira for trying to help me.....
Jump to solution
18 Replies
LeandroFerreira
LeandroFerreira17mo ago
->after(function ($record) {} ) ?
dyo
dyoOP17mo ago
i've tried with $record, but it contains newly added record in main table.. i need to use the data from the form that isn't added to the main table..
LeandroFerreira
LeandroFerreira17mo ago
sorry, I didn't notice that it is a table action where are you using this action? why isn't the $data working?
dyo
dyoOP17mo ago
the action is in relation manager.. i tried using $data, but the value is similar to $record.. the only difference is $record is in object, meanwhile $data is in array..
LeandroFerreira
LeandroFerreira17mo ago
ok but why $data isn't working? Is setoran_id present in the $data? what is the issue?
dyo
dyoOP17mo ago
@Leandro Ferreira to give more picture of my case, the blue section is going to be inserted in main table, we can say table_A.. but the red section, which is setoran_id, should be inserted to table_B, using table_A_id as foreign key what should i do?
dyo
dyoOP17mo ago
i'm using checkboxlist for setoran_id
awcodes
awcodes17mo ago
Why not just use a standard relationship and just let it save normally. Then you wouldn’t have to do all this.
dyo
dyoOP17mo ago
the relationship from table_A to table_B is hasmany so in the model of table_A, table_A hasmany table_B,, if i use the relationship(), i got error Filament\Forms\Components\CheckboxList::getRelationship(): Return value must be of type ?Illuminate\Database\Eloquent\Relations\BelongsToMany, Illuminate\Database\Eloquent\Relations\HasMany returned
awcodes
awcodes17mo ago
Ah. A form lifecycle hook might be better then so you have full control over how the relationship is saved.
dyo
dyoOP16mo ago
i'm struggling to get the checkbox field value in after() at CreateAction class how can i do it?
awcodes
awcodes16mo ago
what does your code look like?
dyo
dyoOP16mo ago
you can see in the beginning of this thread is it not clear enough? what other code you need to see?
awcodes
awcodes16mo ago
if you unset if from the array when you fill then form then how can it be in the data after?
dyo
dyoOP16mo ago
i don't need setoran_id value in the main form.. i need it in after().. i've tried to store the $data value to new array variable, and unset the new variabel, like this..
$newData = $data;
unset($newData['setoran_id']);

return $newData;
$newData = $data;
unset($newData['setoran_id']);

return $newData;
but when i vardump $data in after(), it contains the properties of the new record in the main model. what should i do?
awcodes
awcodes16mo ago
is setoran_id the id of the parent record?
dyo
dyoOP16mo ago
no.. it's from other table.. example of my schema is something like this.. tableA (main model) id tableB id tableA_id setoran_id tableB is a pivot between tableA and setoran_table
Solution
dyo
dyo16mo ago
got it, i'm using $livewire->mountedTableActionData to get the forms value in after().. thanks for @awcodes and @Leandro Ferreira for trying to help me..
Want results from more Discord servers?
Add your server