dongliao2011 2014-08-22 16:13
浏览 33
已采纳

使用雄辩的模型来解决视图和控制器问题

I am using two eloquent models alpha and beta. I am having trouble with the controller and the view. Alpha is designed to have multiple betas and their is a hasMany relationship established. When redirected to the show page they should see the alpha and the beta data by alpha_id. The code I am currently using is pulling an error and after looking in the book and online I can not figure out how to fix it.

Here is the controller code:

public function display($alpha_id)
{
    return View::make('alpha.show')->with([
        'alpha' => $this->alphaRepository->findBy($alpha_id),
        $alpha->alphaRecord->getBeta(),
    ]);
}

Here is the view:

<p>{{ $alpha }}</p>

@foreach($alpha->Betas() as $beta)
<p>Beta: <br />{{ $beta }}</p>
@endforeach
  • 写回答

1条回答 默认 最新

  • dongyangben6144 2014-08-22 16:49
    关注

    The problem is how you call the with method, try to set the $alpha variable first:

    public function display($alpha_id)
    {
        $alpha = $this->alphaRepository->findBy($alpha_id);
        return View::make('alpha.show')->with('alpha',$alpha);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀