I have two different delivery addresses for each order:
- Billing Address
- Delivery address
Both of them have the same fields, so I created only one model for them Address.
Models:
Each order contains two fields:
- invoice_address
- delivery_address
I want each of these fields to point either to the same address (if the user wants the goods to be sent to the address of the invoice), or to two different addresses (if the delivery address is different from the address of the invoices).
How do I create relationships for this purpose?
Here is what I tried:
Order.php
public function orderAddress() {
return $this->hasOne('App\Address');
}
public function deliveryAddress() {
return $this->hasOne('App\Address');
}
Address.php
public function order() {
return $this->belongsTo('App\Order');
}
But I can't figure out how to assign two different addresses to the same order.
hasMany(), , , Address.