【问题标题】:Call to undefined method Illuminate\Database\Query\Builder::only_full_group_by()调用未定义的方法 Illuminate\Database\Query\Builder::only_full_group_by()
【发布时间】:2017-01-18 06:15:01
【问题描述】:

我正在使用 laravel 5.3。我在运行查询时遇到问题。我正在尝试进行 groupby 查询,但它不起作用,并且出现错误,例如调用未定义的方法 Illuminate\Database\Query\Builder::only_full_group_by()。我的代码喜欢

public function showcart()
{

        $cart = DB::table('cartshow')->only_full_group_by('pro_id')->get(); die();

        $i = 1;
        foreach($cart as $tt)
        {

            $count = DB::table('cartlist')->where('pro_id',$tt->pro_id)->sum('qnty');

            $sel_pro= DB::table('product') -> where('id',$tt->pro_id)->first();

            $proname = $sel_pro->name;
            $price = ($sel_pro->price) * $count;

      echo $cartdata  ="<tr>
                                <td>$proname<br><small>Swaminarayan, Extra Hot, Cheese</small></td>
                                <td style='vertical-align:middle'>
                                <input type='button' value='-' onclick='qtyminus($tt->pro_id);' class='qtyminus' field='quantity' />
                                <input type='text' name='quantity' value='$count' class='qty' id='txt$tt->pro_id'/>
                                <input type='button' value='+' onclick='qtyplus($tt->pro_id);' class='qtyplus' field='quantity' />
                                </td>
                                <td class='text-right' style='vertical-align:middle'><button data-id ='$tt->pro_id' type='button' class='btn btn-xs btn-info'><i class='fa fa-remove'></i></button></td>
                            </tr>";

    }   

}   

【问题讨论】:

  • 我在 Laravel 中找不到任何 only_full_group_by 方法,我错过了什么吗?您可以发布对您方法的引用吗?
  • 你不能使用这样的方法。 Laravel QueryBuilder 没有定义该方法。因为,您的链接指向 5.7 版 only_full_group_by 是默认的。因此,请改用groupBy()

标签: laravel laravel-5 laravel-5.2


【解决方案1】:

only_full_group_by 是 MySQL 模式之一。您不能在 QueryBuilder 上调用 only_full_group_by,因为 QueryBuilder 中没有定义任何 only_full_group_by 方法。
你在 Laravel 中使用 Group By 使用 groupBy() 方法。

$cart = DB::table('cartshow')->groupBy('pro_id')->get();

因为在 cmets 中您提供了 MySQL link of version 5.7 only_full_group_by 是默认模式。

如果你想操作 MySQL 模式,这里是 reference

【讨论】:

  • 如果我使用 groupby,我得到了那个错误。 cartshow.id' 在功能上不依赖于 GROUP BY 子句中的列;这与 sql_mode=only_full_group_by 不兼容(SQL:select * from cartshow group by pro_id
  • @vjBDT 在您的config/database.php 中使用'strict' =&gt; false, 禁用连接中的严格模式
猜你喜欢
  • 2014-04-23
  • 2020-01-04
  • 2018-10-03
  • 1970-01-01
  • 2019-04-02
  • 2016-11-25
  • 2017-07-19
  • 2018-05-11
  • 2014-09-01
相关资源
最近更新 更多