我尝试使用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'
我无法理解使用laravel 5.1是什么问题,但是我不认为ut会有问题
答案 0 :(得分:0)
对于派生列,您必须使用having()
:
->having('x', '<', 24)