我是新来laravel,我试图从明确的问题 here通过嵌套阵列控制器与查看laravel
我控制器类似如下:
foreach($users as $user){
$message[] = Model::where('id',$user->id)->get();
}
$data['tests'] = $message;
return View::make('user.index', $data);
我的看法是:
@foreach($tests['message'] as $test)
id : {{$test->id}}
@endforeach
这给了我Undefined index: message
我已经在控制器中转储了$data
。我的数组如下所示。在return语句之前,我将var_dump放置在控制器中。我的var_dump($data)
显示:
array(1) {
["tests"] => array(2) {
[0] => object(Illuminate\ Database\ Eloquent\ Collection) #515 (1) { ["items":protected]= > array(2) {
[0] => ["attributes": protected] => array(14) {
["id"] => string(3) "12"....
}
}
[1] => object(Illuminate\ Database\ Eloquent\ Collection) #515 (1) { ["items":protected]= > array(2) {
[0] => ["attributes": protected] => array(14) {
["id"] => string(3) "12"....
}
}
}
我做错了什么。请帮助我
你能证明你的模型结构?这取决于你的模型。 –
它只包含表名 – m2j
那么,你的消息来自何处?如果你的数组中不存在key(消息),你想如何使用这个键? –