【问题标题】:Alias in select giving error选择给出错误中的别名
【发布时间】:2015-09-14 03:34:06
【问题描述】:

我的查询是这样的..

$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 为什么?

【问题讨论】:

    标签: php mysql laravel blade


    【解决方案1】:

    您的查询似乎是正确的,我建议您检查一下 1)如果您加入了正确的查询。 2)检查您是否正确提及

    groupBy('categories.name')

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-14
      • 1970-01-01
      相关资源
      最近更新 更多