如何从laravel中的杂交关系中选择特定字段?

如何从laravel中的杂交关系中选择特定字段?,laravel,laravel-5,eloquent,Laravel,Laravel 5,Eloquent,嗨,我有一个带有postgress连接的模型“Trip”,另一个带有mongodb连接的模型“ComponentValue” 我创建了一个查询来检索组件值如下的trips public function getVehicleTrips($vehicleID, $filters = null, $withPaginate = true) { try { $query = Trip::query() ->where('vehicle_id',

嗨,我有一个带有postgress连接的模型“Trip”,另一个带有mongodb连接的模型“ComponentValue”

我创建了一个查询来检索组件值如下的trips

public function getVehicleTrips($vehicleID, $filters = null, $withPaginate = true)
{
    try {

        $query = Trip::query()
            ->where('vehicle_id', '=', $vehicleID)
            ->with('heightsDamagedComponentValue')
            ->with('lowestDamagedComponentValue')
            ->with('heightsDamagedComponentValue.componentType')
            ->with('lowestDamagedComponentValue.componentType');


        $query = $this->applyTripsDatesFilters($query, $filters);



        if ($withPaginate) {
            $query = $query->paginate(Helpers::getKeyValue($filters, 'limit', 10));

        }

        $query = $query->sortByDesc('heightsDamagedComponentValue.damage')->values();

        $result = $query;

        return $result;

    } catch (\Exception $e) {

        return false;
    }
}
已检索数据,但heightsDamagedComponentValue有一些文件,我不想将它们包含在结果中,即使我不想包含在查询选择中

那么,如何指定要从mongo关系heightsDamagedComponentValue检索的某些字段

我已经试过了,并尝试添加

 protected $guarded = ['id', 'data'];
对于
ComponentValue
模型,但它也不起作用

heightsDamagedComponentValue方法是

public function heightsDamagedComponentValue()
{
    return $this->hasOne(ComponentValue::class)->orderBy('damage', 'desc');
}

请提供任何帮助并提前表示感谢

这很简单,只要将选择添加到关系中,方法就会选择任何类似的字段

public function heightsDamagedComponentValue()
{
    return $this->hasOne(ComponentValue::class)
        ->select([
            'trip_id',
            'vehicle_id',
            'component_type_id',
            'damage'
        ])
        ->orderBy('damage', 'desc');
}