【问题标题】:multiple join laravel eloquent多重连接 laravel 雄辩
【发布时间】:2014-07-01 08:56:08
【问题描述】:

关于 Laravel 的 Eloquent ORM 的问题。我已经看过了,如果我错过了类似的问题,我深表歉意。

这些是我的模型:

类 Formatos 扩展 Eloquent { 公共函数 preguntas() { return $this->hasMany('\encuesta\Preguntas', 'fenc_id'); } } 类 Preguntas 扩展 Eloquent { 公共功能替代品() { 返回 $this->hasMany('\encuesta\Alternativas', 'alt_id'); } } 类 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)
    );
}

我想要以下结果:

格式 form_id 表格信息 ... 孕妇 preg_id preg_descip ... 另类 alt_id alt_alterna ……

我发现了,我没有很好的结果,请有人帮助我

【问题讨论】:

    标签: php laravel eloquent


    【解决方案1】:

    你可以试试这个:

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

    【讨论】:

      猜你喜欢
      • 2018-06-03
      • 2020-11-16
      • 2019-06-09
      • 2018-02-10
      • 2022-01-15
      • 1970-01-01
      • 2018-06-02
      • 2021-09-15
      • 1970-01-01
      相关资源
      最近更新 更多