sql - Laravel: How to do Inverse HasManyThrough? -


i have 3 tables. want display data cms_planner table topic name cms_topic table. achieve that, need go through cms_subject table.

i want use belongstomany have cms_subject table holds foreign key cms_planner , foreign key cms_topic. table name not represent pivot key.

i want use hasmanythrough doesn't work. i'm thinking inverse hasmanythrough.

how can achieve that?

1. cmsplanner
i. planner_id
ii. subject_id
iii. date_start

2. cmssubject
i. subject_id
ii. topic_id

3. cmstopic
i. topic_id
ii. topic name

in cmsplanner model

public function subject(){   return $this->hasmanythrough(     'app\cmstopic',     'app\cmssubject',     'topic_id', 'topic_id', 'planner_id');} 

in cmsplanner controller

cmsplanner::with('subject')->get(); 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -