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

shadrix's avatar
Level 12

Naming question: What is the appropriate short name for BillingSeller?

Currently, in my Order Table, I've got the relationships billingSeller and billingBuyer.

I would like to change it so that billing is always the buyer data and **** for the seller.

I have no idea how I could name it, do you have any idea?

Thank you!

0 likes
5 replies
aurawindsurfing's avatar

Hi,

@shadrix as @jeffreyway says, name as you would speak it.

First: OrderTable? Is this a Table that has such name? If so it is already a table so just name it orders, if this is a Model then for sure it should not be named OrderTable but simply Order.

Second: relationship from Order will be as you speak it: Order hasOne seller and belongsToMany buyer, belongsTo Product and so on. So You would have something like:

Order:

public function billings()
    {
        return $this->hasMany('App\Billing');
    }

Billing:

public function seller()
    {
        return $this->belongsTo('App\Seller');
    }

public function buyer()
    {
        return $this->hasMany('App\Buyer');
    }

and so on. I hope it makes sense.

2 likes
martinbean's avatar

@shadrix If someone is selling something, they are a Merchant. If someone is buying something, they are a Customer.

You can alter the foreign keys in your relationships to accommodate these names:

class Order extend Model
{
    public function customer()
    {
        return $this->belongsTo(User::class, 'customer_id');
    }

    public function merchant()
    {
        return $this->belongsTo(User::class, 'merchant_id');
    }
}
1 like
shadrix's avatar
Level 12

@aurawindsurfing and @martinbean, sorry for the miscommunication... ?

So I try to explain it. In Order.php I have the relationships seller() and buyer() (or @martinbean's naming scheme is also nice)

However, for each Order, I'm saving the Seller Address + Name data and the Buyer Address + Name data.

I'm using a polymorphic table called addresses to save all kinds of addresses.

To save the addresses of the orders I have two extra models OrderBillingSeller and OrderBillingBuyer. That is important for morphing the right type.

Currently, I'm using the naming scheme:

//in Order.php
public function *****(can't find a good name)()
{
    return $this->hasOne('App\OrderBillingSeller');
}

public function billing()
{
    return $this->hasOne('App\OrderBillingBuyer');
}

I'm not really happy about it, but I associate billing as the invoice/billing for the buyer and for the seller I'm not sure what to use.

So to get the billing address for example I'm calling:

$order->billing->address->postcode; 

Btw thank you for your help nonetheless!

martinbean's avatar

@SHADRIX - The relationship you can’t find a good name for, what does it represent? Why do you need that address?

If you can answer that question, you can probably also find the name of that relationship :)

1 like
D9705996's avatar

I quite like the ...able format

What about purchasable and sellable fof your relationships. If you ard finding it hard to name something (which can be hard) it often a sign you might be missing a reafctor or redesign

1 like

Please or to participate in this conversation.