guillermo_rojas's avatar

Circular reference many to many

Hi everyone.

I was developing a project, with voyager. I have this table news. So I created a model New.php. Everything is working like a charm. Our client would like to relate and show, news, to other similar news. So there's a problem. How to work and manage with circular references and many to many relationship?

Any ideas would be appreciated.

0 likes
2 replies
Vilfago's avatar

Never tried, but should work

table news_related - 2 column

  • base_news_id
  • related_news_id
class New extends Model
{
    public function relatedNews(){
        return $this->belongsTo('App\New', 'table_news_related', 'base_news_id', 'related_news_id');
    }
}
1 like

Please or to participate in this conversation.