链接视图和控制器的问题

时间:2014-08-22 13:25:32

标签: php laravel view laravel-4 controller

这是我在示例视图中遇到的错误:

Undefined variable: sampleRecord

这是控制器代码:

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

这是视图代码:

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

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

1 个答案:

答案 0 :(得分:4)

你的控制器应该是:

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