Php Laravel 5.3:当我使用了急切嵌套关系时,如何获得直接计数?
在我的控制器中,我使用了:Php Laravel 5.3:当我使用了急切嵌套关系时,如何获得直接计数?,php,laravel-5.3,Php,Laravel 5.3,在我的控制器中,我使用了: ->with('city.location.propertyCount') 在模型中,方法定义为: public function propertyCount() { return $this->property() ->selectRaw("location_id, count(*) as property_count") ->groupBy('location_id'); } 我在对象中得到的响
->with('city.location.propertyCount')
在模型中,方法定义为:
public function propertyCount() {
return $this->property()
->selectRaw("location_id, count(*) as property_count")
->groupBy('location_id');
}
我在对象中得到的响应:
"property_count":
[
{
"location_id": XXX,
"property_count": 1
}
]
"property_count": 1
我希望计数在响应对象中的显示方式:
"property_count":
[
{
"location_id": XXX,
"property_count": 1
}
]
"property_count": 1
返回$this->property()->selectRaw(“count(*)as property_count”)->groupBy('location_id')->first()@Builder.php第2451行中的JYoThI BadMethodCallException:调用未定义的方法Illumb\Database\Query\Builder::AddagerConstraints(),尝试以下操作->groupBy('location_id')->value('property_count')@JYoThI不工作,Builder.php第502行中出现FatalThrowableError:调用integer上的成员函数AddagerConstraints()