我在模型房里计算了房产的价格。
protected $appends = ['price'];
public function getPriceAttribute()
{
if ($this->action) return $this->action_price_per_meter*$this->area;
return $this->price_per_meter*$this->area;
}当我在这个虚拟区域过滤房间时..。
$rooms = Room::where('price','<',100000)->get();当然,我没有找到错误的列“价格”。
如何用Laravel方法解决这一问题?
发布于 2016-11-13 19:02:37
segment有一个whereRaw方法,它允许您手动构造查询的该段。
在您的示例中,需要与SQL中的模型方法等效:
->whereRaw('price_per_meter * area < 100000')根据您的action列所做的事情,这将更加复杂,但这应该是一个起点。
https://stackoverflow.com/questions/40577568
复制相似问题