I have two models, an order model and an address model. Each line in the orders table has an address ID which correlates to a line in the address table.
in the order model...
public function address()
{
return $this->hasOne(OrderAddress::class);
}
in the address model...
public function order()
{
return $this->hasMany(Order::class);
}
However, I want to access the address from the order model
$order->address
This shows an error becuase I do not have any order_id fields in the address table. Eventually I want it to be possible to check if the address already exits in the table (i.e. for repeat orders from the same customer) and then I can reuse this same row across multiple orders.
So in summary, an order can only ever have 1 address but an address can have many orders. I have setup my models like this (I think) but the following error is thrown:
Column not found: 1054 Unknown column 'order_addresses.order_id' in 'where clause'