Laravel pivot: Get model from withPivot() -


i'm building application using laravel 4 have stumbled across problem pivot tables.

i've got user model, establishment model, & studylevel model.

for moment find establishment user has been @ use following code in user model:

public function establishments() {     return $this->belongstomany('establishment')->withpivot('start', 'stop', 'study_level_id')->withtimestamps(); } 

the establishment_user (pivot) table has following columns:

id | establishment_id | user_id | start | stop | study_level_id 

to list of establishments user use following in controller:

$establishments = $user_repo->find($user_id)                 ->with(['establishments', 'establishments.usersubjects' => function ($query) use ($user)                 {                     $query->where('user_id', $user->id);                 }])                 ->get(); 

my problem response gives me id of studylevel have information studylevel model. possible information studylevel table using withpivot() ?

thanks in advance, appreciated.

the ideal way have model pivot table. there alternatives whereby can have relationships defined in models, using field pivot_study_level_id, wouldn't work in every situation , more trouble it's worth.

just setup model establishment\user , let handle relationships.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -