带有model::和附加列的laravel问题

vuktfyat  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(267)

我尝试添加带有model::with的附加列

$pitchChech =  Pitch::with(['prices'=>function ($query){
            $query->select('*',\DB::Raw("(select sum(HOUR(TIMEDIFF(valid_to ,valid_from))) from pitch_price as xpitch_price where pitch_id = pitch_price.pitch_id ) as x "))
            ->whereRaw(" x < ?",[24]);
        }])->get();
      dd($pitchChech);

我有这个输出

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'x' in 'where clause'

我不明白是什么问题,我使用拉维5.1,但我不认为有问题与ut

zqry0prt

zqry0prt1#

对于派生列,必须使用 having() :

->having('x', '<', 24)

相关问题