Insert to one table from another table
Hi, in my filament project i have two tables 'Loan' and 'Payment'. When i insert data to Loan table using LoanResource Form I also want to send some of the data to Payment table. I tried using afterCreate() life cycle hook, but i could not pass data to it. Is there any other way, like custom controller.
10 Replies
Can you explain what you are trying to do? What does it mean to send data from the Load table to the Payment table?
i have columns like loan_amount, loan_date on Loan Table and i have the same column on Payment Table as well. I want to send those same data as soon as Loan is created because i want that data to be as the initial balance for Payment.
Does the payment get created automatically when you create a loan?
i have the above code in mutateFormDataBeforeCreate but i could not create payment because the payment is referencing to loan
i tried using afterCreate() but i cannot pass the loan data which is just created
Right, I think
afterCreate()
is probably what you need... can you show me what you have tried?
i tried to pass the value to afterCreate but i am getting error too few arguments
afterCreate()
doesn't receive any parameter... you can read it from $this->data['id']
I thinkok let me try
i still get Integrity Constraint violation error, since loan_id on Payment is referencing to loan_id on Loan Table.
$this->record->id
my mistake, it works now. Thank you so much, i have been trying for the whole day. Thank you alot.