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
Solution:Jump to 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.....
18 Replies
->after(function ($record) {} )
?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..
sorry, I didn't notice that it is a table action
where are you using this action?
why isn't the
$data
working?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..
ok but why
$data
isn't working? Is setoran_id present in the $data?
what is the issue?@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?
i'm using checkboxlist for setoran_id
Why not just use a standard relationship and just let it save normally. Then you wouldn’t have to do all this.
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
Ah. A form lifecycle hook might be better then so you have full control over how the relationship is saved.
i'm struggling to get the checkbox field value in after() at CreateAction class
how can i do it?
what does your code look like?
you can see in the beginning of this thread
is it not clear enough?
what other code you need to see?
if you unset if from the array when you fill then form then how can it be in the data after?
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..
but when i vardump $data in after(), it contains the properties of the new record in the main model.
what should i do?
is setoran_id the id of the parent record?
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
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..