问题出在foreach循环中我可以取这个值:$gro -> name
但是当我尝试这个$gro -> id
时不工作只返回null。这是我的功能:
$adminIdCondition = function($q){
$q->where('project_group.admin_id', Auth::user()->admin_id)
->where('project_id', $this->id)
->where('user_id',Auth::id())->where('actived',0);
};
$groups = Group::with(['projects' => $adminIdCondition])
->whereHas('projects', $adminIdCondition)
->get();
$questions = array();
foreach($groups as $gro){
$questions[] = array(
$gro->name => Question::where('group_id',$gro->id)->lists('text')
);
}
return $questions;
此外,如果我转储$ groups,我可以找到id值...