Problems linking view and controller

ⅰ亾dé卋堺 提交于 2019-12-13 03:01:17

问题


This is the error I am getting on the sample view:

Undefined variable: sampleRecord

This is the controller code:

 public function show($sample_id)
 {
    return View::make('samples.show')->with([
        $this->sampleRepository->find($sample_id),
        $this->sampleRecord->getSamplePartNumberRecord,
    ]);
 }

This is the view code:

<p>{{ $sampleRecord }}</p>

@foreach($sampleRecord->SamplePartNumbers() as $samplePartNumberRecord)
<p>Sample Part Number: <br />{{ $samplePartNumberRecord }}</p>
@endforeach

回答1:


your controller should be:

public function show($sample_id)
{
    return View::make('samples.show')->with([
        "sampleRepository" => $this->sampleRepository->find($sample_id),
        "sampleRecord" => $this->sampleRecord->getSamplePartNumberRecord,
    ]);
 }


来源:https://stackoverflow.com/questions/25448157/problems-linking-view-and-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!