关于Laravel 的 Eloquent ORM 的问题。我已经看过了 SO,如果我错过了类似的问题,我深表歉意。
这些是我的模型:
类 Formatos 扩展 Eloquent {
公共函数 preguntas()
{
返回 $this->hasMany('\encuesta\Preguntas', 'fenc_id');
}
}
类 Preguntas 扩展 Eloquent {
公共函数替代()
{
返回 $this->hasMany('\encuesta\Alternativas', 'alt_id');
}
}
Class Alternativas 扩展了 Eloquent{
}
我的控制器的方法是:
public function show($id)
{
$formatos = encuesta\Formatos::find($id);
$preguntas = $formatos->preguntas;
$preguntas->alternativas;
return View::make(
'encuesta.formato.pregunta.show',
array('formatos' => $formatos)
);
}
Run Code Online (Sandbox Code Playgroud)
我想要以下结果:
格式
form_id
表格信息
...
怀孕
preg_id
preg_descip
...
替代方案
alt_id
alt_alterna
....
我发现了,我没有得到好的结果,请有人帮助我