samedi 5 décembre 2020

How to get row property from laravel object?

I am using api which is returning object in response but it is not letting me to access the property rows how I can fetch this property?

here is the response

FinalBytes\GoogleDistanceMatrix\Response\GoogleDistanceMatrixResponse {#404
  -destinationAddresses: array:1 [
    0 => FinalBytes\GoogleDistanceMatrix\Response\Address {#403
      -address: "Maistraße 10, 80337 München, Duitsland"
    }
  ]
  -originAddresses: array:1 [
    0 => FinalBytes\GoogleDistanceMatrix\Response\Address {#388
      -address: "Van Bronckhorststraat 94, 5961 SM Horst, Nederland"
    }
  ]
  -responseObject: {#402
    +"destination_addresses": array:1 [
      0 => "Maistraße 10, 80337 München, Duitsland"
    ]
    +"origin_addresses": array:1 [
      0 => "Van Bronckhorststraat 94, 5961 SM Horst, Nederland"
    ]
    +"rows": array:1 [
      0 => {#391
        +"elements": array:1 [
          0 => {#398
            +"distance": {#389
              +"text": "676 km"
              +"value": 676254
            }
            +"duration": {#392
              +"text": "6 uur 50 min."
              +"value": 24582
            }
            +"status": "OK"
          }
        ]
      }
    ]
    +"status": "OK"
  }
  -rows: array:1 [
    0 => FinalBytes\GoogleDistanceMatrix\Response\Row {#407
      -elements: array:1 [
        0 => FinalBytes\GoogleDistanceMatrix\Response\Element {#406
          -status: "OK"
          -duration: FinalBytes\GoogleDistanceMatrix\Response\Duration {#396
            -text: "6 uur 50 min."
            -value: 24582
          }
          -distance: FinalBytes\GoogleDistanceMatrix\Response\Distance {#405
            -text: "676 km"
            -value: 676254
          }
        }
      ]
    }
  ]
  -status: "OK"
}

function is here

public function addDistanceToProvider($provider,$request)
    {

        $distanceMatrix = new GoogleDistanceMatrix('');
         $distance = $distanceMatrix
                ->addOrigin('Van Bronckhorststraat 94, 5961SM Horst, The Netherlands')
                ->addDestination('Maistraße 10, 80337 München, Deutschland')
                ->setMode(GoogleDistanceMatrix::MODE_DRIVING)
                ->setLanguage('nl-NL')
                ->setUnits(GoogleDistanceMatrix::UNITS_METRIC)
                ->setAvoid(GoogleDistanceMatrix::AVOID_FERRIES)
                ->sendRequest();
          return $distance->origin_addresses;     
    }

Error

message: "Undefined property: FinalBytes\GoogleDistanceMatrix\Response\GoogleDistanceMatrixResponse::$rows"


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

Aucun commentaire:

Enregistrer un commentaire