multiple join laravel eloquent

multiple join laravel eloquent

Question about Laravel’s Eloquent ORM. I’ve had a look on SO already, apologies if I’ve missed a similar question.

These are my models:

class Formatos extends Eloquent {

    public function preguntas()
    {
        return $this->hasMany('encuestaPreguntas', 'fenc_id');
    }
}
class Preguntas extends Eloquent {

    public function alternativas()
    {
        return $this->hasMany('encuestaAlternativas', 'alt_id');
    }
}
class Alternativas extends Eloquent{


}

My controller’s method is:

public function show($id)
{
    $formatos = encuestaFormatos::find($id);
    $preguntas = $formatos->preguntas;
    $preguntas->alternativas;

    return View::make(
        'encuesta.formato.pregunta.show', 
        array('formatos' => $formatos)
    );
}

I want the following result:

FORMATO
    form_id
    form_info
    ...
    PREGUNTAS
        preg_id
        preg_descip
        ...
        ALTERNATIVAS
            alt_id
            alt_alterna
            ....

I found out and I have not had good results, please someone help me

You may try this:

$formatos = encuestaFormatos::with('preguntas.alternativas')->find($id);
.
.
.
.