select 中的别名给出错误
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)
为什么视图无法识别 catcompid?
你的查询似乎是对的,我建议你可以检查一下
1)如果您加入了正确的查询。
2) 检查你是否正确提到
groupBy('categories.name')
条件。
如果您需要进一步的帮助,请告诉我。
我的查询是这样的..
$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)
为什么视图无法识别 catcompid?
你的查询似乎是对的,我建议你可以检查一下 1)如果您加入了正确的查询。 2) 检查你是否正确提到
groupBy('categories.name')
条件。 如果您需要进一步的帮助,请告诉我。