选择给定错误中的别名


Alias in select giving error

我的查询是这样的。。

$query = DB::table('categories')
->select('categories.name','category_company.id as catcompid ','category_company.company_id','category_company.category_id')
->leftJoin('category_company', function($leftJoin){
$leftJoin->on('categories.id', '=', 'category_company.category_id');
})
->groupBy('categories.name')
->get();

我的观点是这样的。。

 @foreach($top as $tp)  
              <tr>
                  <td>{{ $tp->name }}</td>
                  <td>
                        {{ $tp->catcompid }}
                    </td>
                </tr>
@endforeach 

它给我的错误就像这个

ErrorException in 7a50b25fc86bfddf956cb4108a130dd2 line 42: Undefined property: stdClass::$catcompid (View: /var/www/test/resources/views/top/index.blade.php)

观点不认同猫为什么?

您的查询似乎正确,我建议您检查一下1) 如果您已加入右侧查询。2) 检查你是否正确地提到

groupBy('categories.name')

条件。如果你需要进一步的帮助,请告诉我。