php - Laravel Model Relationship. which one? -


hey there should start given db work with. not sure relationship used. need able name of categories assigned articles.

basically articles <> article_categories <> categories

article_categories being connector

articles |id|header|body|ect...|

categories |id|parent_group|name|

article_categories |article_id|category_id|

so thought maybe hasmanythrough got errors. did arguments wrong.

what tried first inside articles model (got error this)

public function category(){ return $this->hasmanythrough('app\categories' , 'app\article_categories' ,'article_id' , 'category_id'); }

hope explain situation. need use has many through or on complicating this?

-thanks

no need hasmanythrough

belongstomany need.

public function category(){     return $this->belongstomany('app\categories' , 'article_categories' ,'article_id' , 'category_id'); } 

Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -