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

JustSomeoneWhoLovesWatchingJapaneseWeatherRepotto's avatar

How save records on tables with Parent->child->child relationship

Let's say I have three tables.

table A
--------------------
id
description

table b
--------------------
id
a_id
description

table c
--------------------
id
b_id
description

Whenever I do

$a->save();
$a->b()->save();
$a->c()->save();

I get the error BadMethodCallException with message 'Call to undefined method Illuminate\Database\Eloquent\Relations\HasManyThrough::save()'

My a model have a hasManyThrough(C, B) relationship;

0 likes
3 replies
jlrdw's avatar

I once had similar, it's basically a double one to many. In my case I had Loads with children: picks and drops.

jlrdw's avatar

Give it a try, if that's what's needed. It worked in my case, each child had a load_id column.

Of course queries were distinguished by if it was a pick or a drop for the truck (LTL).

Just a side note, this was back in my Java days not laravel, but query techniques would be similar.

Please or to participate in this conversation.