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

panthro's avatar

HasManyThrough (but one relationship is a belongsTo)

A producer hasMany productions.

A production belongsTo a role.

Producer:

id | title

Productions:

id | producer_id | production_role_id

Roles:

id | title

Can I get the role with a hasManyThrough on the producer model?

I am aware hasManyThrough is for hasMany relationships, but I cannot remember where I read it but I thought you could swap the argument/keys to make it work like this?

0 likes
1 reply
DhPandya's avatar

@panthro The Laravel docs has clear answer for it.

/**
 * Get the user that owns the phone.
 */
public function user(): BelongsTo
{
    return $this->belongsTo(User::class, 'foreign_key', 'owner_key');
}

Please or to participate in this conversation.