Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Chron's avatar
Level 6

Is there a way to create a record that has one or more than a level deep?

I have 3 tables: User, Receipt, and Payment

User has many payment that has one receipt.

Is this possible?

$user->payment()->receipt()->create();
0 likes
1 reply
fylzero's avatar

You don't really need to reference this in this way... I suppose it is possible... but to create a receipt, you'd just pass it the payment_id.

$user = Auth::user();
$payment = Payment::create('description' => 'Paid for service');
Receipt::create(['payment_id' => $payment->id, 'amount' => 300]);

The receipt has a relationship to payment... payment to user.

Each thing should exist in a cascade anyway.

24 likes

Please or to participate in this conversation.