报这个错误Property [id] does not exist on this collection instance.
var_dump($res2)可以正常显示 var_dump($res->id)这样不会报错 但是var_dump($res2->id)就报这个错 id明明有数据的啊 这是为什么?
$res=DB::table('blog')->get();
foreach($res as $k=>$v){
$uid=$v->uid;
$res2=DB::table('comment')->where('uid',$uid)->get();
var_dump($res2->id);
}
下面是得到的$res2的数据
object(Illuminate\Support\Collection)#184 (1) { ["items":protected]=> array(1) { [0]=> object(stdClass)#180 (5) { ["id"]=> int(1) ["uid"]=> int(5555) ["content"]=> string(112) "我我我我我喔喔喔喔我我我哦我问我我我我问喔喔喔喔喔喔哦我问问哦我哦我我问 我" ["href"]=> string(6) "111111" ["time"]=> int(1300215201) } } } object(Illuminate\Support\Collection)#186 (1) { ["items":protected]=> array(0) { } }
如
红心K
所说,$res2
是collection
对象,里面的元素是数组,数组里的每一个元素是comment
记录的stdClass
形式;你可以这样写