I need help adding a pivot record and related child records in Laravel. I would like to do it using ORM if possible. The concept here is potential donors attend fundraisers and make donations, which will be comprised of one or more designations. My tables are like so (simplified):
donor:
id
name
fund_raiser:
id
date
donation:
id
donor_id
fund_raiser_id
monetary_type
designation:
id
donation_id
category
amount
I can insert the pivot record manually as follows:
// assume both donor and rundraiser records already exist
$donor = Donor::find($donorID);
$fundraiser = FundRaiser::find($fundraiserID);
// create the pivot record
$donation = Donation::create(['donor_id' => $donor->id, 'fundraiser_id' => $fundraiser->id, 'date' => 'somedate']);
// now add a designation
$designation = new Designation(['Category' => 'General', 'Amount' => '100']);
$donation->designations()->save($designation);
Or I can create the pivot record in a more ORM kind of way:
$fundraiser->donors()->save($donor)
But now I don't know how to insert the designation, since I don't know the id of the pivot record that was just added.