无法从Laravel 5中的MySQL表访问id属性

时间:2015-05-28 15:57:38

标签: php laravel-5

问题出在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值...

0 个答案:

没有答案