我尝试在 Laravel 5.1 中显示带有刀片的嵌套数组,但我不能这样做:
控制器:
public function track($id){
$tracks = track::with('trials.samples')->where('trials_id',$id)->get();
//return $tracks;
return view('Tracks.index',compact('tracks'));
}
Traks.index:
{{ $track['samples']['variety'] }}
返回 $tracks 返回:
[{
"id": 1,
"trials_id": 1,
"date": "2015-12-16",
"comments": "\u0646\u062a\u06cc\u062c\u0647 \u062e\u0627\u0635\u06cc \u0646\u062f\u0627\u0634\u062a\u0647 !",
"created_at": "-0001-11-30 00:00:00",
"updated_at": "-0001-11-30 00:00:00",
"trials": {
"id": 1,
"persons_id": 1,
"samples_id": 1,
"amount": "125000",
"date": "2015-12-09",
"comments": "",
"code": "5CEPY",
"created_at": "2015-12-08 06:46:58",
"updated_at": "2015-12-08 06:46:58",
"samples": {
"id": 1,
"variety": "keyhan",
"supplier_id": 1,
"lot_number": "2550",
"date": "2015-12-11",
"amount": 125000,
"unit_id": 1,
"technical_fact": "\u0641\u0646\u06cc",
"comments": "1",
"file_address": "",
"category_id": 1,
"created_at": "2015-12-08 06:46:34",
"updated_at": "2015-12-08 06:46:34"
}
}
}]
我也试过这段代码,但没有显示:
{{ $track['trials.samples']['variety'] }}
{{ $track->samples['variety'] }}