mercredi 19 avril 2017

Merge two hasOne relation in laravel - Eloquent

public function relationWithId()
{
   return $this->hasOne('App\RelatedProduct', 'product_id', 'id');
}

public function relationWithParent()
{
    return $this->hasOne('App\RelatedProduct', 'product_id', 'parent_id');
}

I have two table one is product and secound is RelatedProduct where related product is connected with products.id and sometime with product.parent_id

so need a third relation where I can merge about both like this

public function relationProduct()
{
   /*****/
}

thanks in advance



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire