带有模型::带有附加列的拉拉维尔普罗普勒姆



>我尝试添加附加列 模型::与

$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'  

我不明白使用 Laravel 5.1 有什么问题,但我认为 UT 没有问题

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

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