问题
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