vendredi 30 août 2019

How to select specific HybridRelations in laravel?

Hi i have on model "Trip" with postgress connection and another model "ComponentValue" with mongodb connection

i have created a query to retrieve trips with component value like this

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;
    }
}

the data are retrieved but the heightsDamagedComponentValue has some fileds that i don't want to include them in the result, even i don't want to be included in the query selection

so how i can specific some fields to retrieved from the mongo relationship heightsDamagedComponentValue ?

i already tried this solution and tried to add

 protected $guarded = ['id', 'data'];

to the ComponentValue model but it didn't work also,

the heightsDamagedComponentValue method is

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

please any help and many thanks in advance



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2ZF0cYq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire