I have a transaction table in database. The relation for the transaction table is, customer can send many transactions. A branch can have many transactions and a transaction handler can serve many transactions. I have defined models and relations. But don't know how to save the relations as save one first will make other fk null. Is there any method to save all at once or my database relation is wrong?
My schema is
And my controller code to save the relation is
//Save models related to transactions
$transaction = new Transaction($request->input('partCTransaction'));
//Customer can have many transactions
$customer->transactions()->save($transaction);
//branch has many reporting entities and a branch handles many transactions
$branch->transactions()->save($transaction);
//A transaction handler handles different transactions
$transactionHandler->transactions()->save($transaction);
Any idea on how to resolve this issue.
My error is
General error: 1364 Field 'branch_id' doesn't have a default value (SQL: insert into `transactions` (`date`, `ref_number`, `customer_id`, `updated_at`, `created_at`) values (, , 9, 2018-06-25 23:36:11, 2018-06-25 23:36:11))