Eloquent Laravel - selectRaw()inHas()'关闭

时间:2015-02-28 18:29:07

标签: php laravel eloquent

我想选择点数之和并将其传递给where子句。以下是我的代码:

    $query->whereHas('evaluations', function ($q) use ($params)
    {
        $q->selectRaw('sum(evaluations.point) as points')
            ->where('points', '>=', $params->point);
    });

但它提醒Column not found: 1054 Unknown column 'points' in 'where clause'

1 个答案:

答案 0 :(得分:1)

您无法为使用SELECT创建的列执行WHERE。您必须使用像->having('points', '>=', $params->point)

这样的HAVING语句