如果我使用选择功能,数据将消失
$regions = Region::select('id', 'place_id', 'formatted_address')
->where('lang', $lang)
->with(['areas' => function($query) {
return $query
->select('id', 'place_id', 'formatted_address') // << the problem is here
->whereNotNull('area1')->whereNull('locality')->whereNull('area2');
}])
->get();
如果删除选择功能,则区域字段将填充数据
关系:
$this->hasMany(Region::class, 'country', 'formatted_address');
答案 0 :(得分:0)
请求中必须包含参与关系的字段
$this->hasMany(Region::class, 'country', 'formatted_address');
->select('place_id', 'country', 'formatted_address')