mercredi 22 mai 2019

Laravel 5.4 relationship - using the right type

I have 3 tables: users, user_addrs, orders

The orders table have these fields: user_id, shipping_addr_id, billing_addr_id

In the UserAddr model I have:

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

In the Order model I have:

public function userShippingAddr()
{
    return $this->belongsTo('App\UserAddr', 'shipping_addr_id');
}

public function userBillingAddr()
{
    return $this->belongsTo('App\UserAddr', 'billing_addr_id');
}

Is this the right way to do it or should I use a different relationship type?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire