Relationship hasOne over two tables

Posted 9 months ago by shadrix

I'm not sure how to solve this problem:

picture

I have an address table and a user_addresses table.

My current relationship looks like this:

public function address()
{ 
    return $this->hasOne(UserAddress::class)
                ->where('is_physical', true);
} 

However, I don't care about the UserAddress. When I write$user->address I want to get the Addresstable that belongs to the UserAddress (like Has One Through).

My api endgoal is to write: $user->address()->create(['street_number' => '25c']). So it creates UserAddress with is_physical => true and the Address table.

Later on I'm doing similar stuff like $order->billing()->create() for is_billing => trueand so on.

Is this somehow possible?

p.S. sorry about the title, I just don't know how to simplify my problem in a title...

Please sign in or create an account to participate in this conversation.