In the Commission.php model you should make your relationship :
...
public function parlamentares() {
return $this->belongsToMany('App\Parlamentar', 'composicao_comissao', 'cod_comissao', 'cod_parlamentar')->withPivot('dat_designacao', 'cod_periodo_comp', 'ind_titular', 'outras colunas da tabela pivot que queiras aceder via esta relacao');
}
...
Parliamentary model.php (optional, since you don’t mention needing this link in the question):
...
public function comissoes() {
return $this->belongsToMany('App\Comissao', 'composicao_comissao', 'cod_parlamentar', 'cod_comissao')->withPivot('dat_designacao', 'cod_periodo_comp', 'ind_titular', 'outras colunas da tabela pivot que queiras aceder via esta relacao');
}
...
EX:
$comissao_1 = App\Comissao::find(1);
You send the data $comissao_1
to the view, and there you can do, ex (I assume you are using template):
@foreach($comissao_1->parlamentares as $par)
{{$par->nome_completo}} -> {{$par->pivot->cod_periodo_comp}}<br>
@endforeach
Note pivot
, is the information (columns) you want to access in the pivot table (composicao_comissao
), cod_periodo_comp
in this case. It is necessary to declare them in the relation within the models, such as the example above.
DOCS
What are the names of the models? To suit what you have
– Miguel
I used in the models the same table names
– Amaro Correa