I currently have the following situation:
- 1 User can belong to multiple municipalities
- Within this relationship -
municipios_usuarios
- I need to also save who made this relationship, ieusuario_id
public function municipios()
{
return $this->belongsToMany('Projeto\DB\Municipio', 'municipios_usuarios')
->withPivot('criado_por_id', 'atualizado_por_id');
}
How do I configure Laravel 5.1 the relationship of this new field so that I can access it in this way (or some other way):
@foreach ($usuario->municipios => $municipios)
{!! $municipio->pivot->criadoPor->nome !!}
@endforeach
The only way I could do this was by doing a join()
manually, however I'd like to use Eloquent .
No more, thank you.
If you need more information let me know.