0
votes

I am working with Laravel 8.0 with the Quickbooks API, When I run a quickbooks query to get all the customers, I get back a response that looks like this.

Array
(
    [0] => QuickBooksOnline\API\Data\IPPCustomer Object
        (
            [Taxable] => true
            [BillAddr] => QuickBooksOnline\API\Data\IPPPhysicalAddress Object
                (
                    [Id] => 2
                    [Line1] => 4581 Finch St.
                    [Line2] => 
                    [Line3] => 
                    [Line4] => 
                    [Line5] => 
                    [City] => Bayshore
                    [Country] => 
                    [CountryCode] => 
                    [County] => 
                    [CountrySubDivisionCode] => CA
                    [PostalCode] => 94326
                    [PostalCodeSuffix] => 
                    [Lat] => INVALID
                    [Long] => INVALID
                    [Tag] => 
                    [Note] => 
                )

            [ShipAddr] => QuickBooksOnline\API\Data\IPPPhysicalAddress Object
                (
                    [Id] => 2
                    [Line1] => 4581 Finch St.
                    [Line2] => 
                    [Line3] => 
                    [Line4] => 
                    [Line5] => 
                    [City] => Bayshore
                    [Country] => 
                    [CountryCode] => 
                    [County] => 
                    [CountrySubDivisionCode] => CA
                    [PostalCode] => 94326
                    [PostalCodeSuffix] => 
                    [Lat] => INVALID
                    [Long] => INVALID
                    [Tag] => 
                    [Note] => 
                )

            [OtherAddr] => 
            [ContactName] => 
            [AltContactName] => 
            [Notes] => 
            [Job] => false
            [BillWithParent] => false
            [RootCustomerRef] => 
            [ParentRef] => 
            [Level] => 
            [CustomerTypeRef] => 
            [SalesTermRef] => 
            [SalesRepRef] => 
            [TaxGroupCodeRef] => 
            [TaxRateRef] => 
            [PaymentMethodRef] => 
            [CCDetail] => 
            [PriceLevelRef] => 
            [Balance] => 239.00
            [OpenBalanceDate] => 
            [BalanceWithJobs] => 239.00
            [CreditLimit] => 
            [AcctNum] => 
            [CurrencyRef] => USD
            [OverDueBalance] => 
            [TotalRevenue] => 
            [TotalExpense] => 
            [PreferredDeliveryMethod] => Print
            [ResaleNum] => 
            [JobInfo] => 
            [TDSEnabled] => 
            [CustomerEx] => 
            [SecondaryTaxIdentifier] => 
            [ARAccountRef] => 
            [PrimaryTaxIdentifier] => 
            [TaxExemptionReasonId] => 
            [IsProject] => false
            [BusinessNumber] => 
            [GSTIN] => 
            [GSTRegistrationType] => 
            [IsCISContractor] => 
            [ClientCompanyId] => 
            [ClientEntityId] => 0
            [IntuitId] => 
            [Organization] => 
            [Title] => 
            [GivenName] => Amy
            [MiddleName] => 
            [FamilyName] => Lauterbach
            [Suffix] => 
            [FullyQualifiedName] => Amy's Bird Sanctuary
            [CompanyName] => Amy's Bird Sanctuary
            [DisplayName] => Amy's Bird Sanctuary
            [PrintOnCheckName] => Amy's Bird Sanctuary
            [UserId] => 
            [Active] => true
            [V4IDPseudonym] => 002098e9355296552b4ab8a26366974b39e91e
            [PrimaryPhone] => QuickBooksOnline\API\Data\IPPTelephoneNumber Object
                (
                    [Id] => 
                    [DeviceType] => 
                    [CountryCode] => 
                    [AreaCode] => 
                    [ExchangeCode] => 
                    [Extension] => 
                    [FreeFormNumber] => (650) 555-3311
                    [Default] => 
                    [Tag] => 
                )

            [AlternatePhone] => 
            [Mobile] => 
            [Fax] => 
            [PrimaryEmailAddr] => QuickBooksOnline\API\Data\IPPEmailAddress Object
                (
                    [Id] => 
                    [Address] => [email protected]
                    [Default] => 
                    [Tag] => 
                )

            [WebAddr] => 
            [OtherContactInfo] => 
            [DefaultTaxCodeRef] => 
            [Id] => 1
            [SyncToken] => 0
            [MetaData] => QuickBooksOnline\API\Data\IPPModificationMetaData Object
                (
                    [CreatedByRef] => 
                    [CreateTime] => 2020-12-31T16:48:43-08:00
                    [LastModifiedByRef] => 
                    [LastUpdatedTime] => 2021-01-07T13:39:32-08:00
                    [LastChangedInQB] => 
                    [Synchronized] => 
                )

            [CustomField] => 
            [AttachableRef] => 
            [domain] => 
            [status] => 
            [sparse] => 
        )

I pass off that data to the view, and then inside my blade template I foreach the customers like so.

        @foreach($customers as $customer)  

        <h1>{{ $customer->GivenName.' '.$customer->FamilyName }}</h1>  
                
        @endforeach

My issue is when I to access the BillAddr inside of my foreach. {{$customer->BillAddr->Line1 }}

        @foreach($customers as $customer)  

        <h1>{{ $customer->GivenName.' '.$customer->FamilyName }}</h1>  
        <h2>address: {{$customer->BillAddr->Line1 }}<h2>
                 
        @endforeach

no matter what I can't seem to access the data, I've tried to access it using different ways, such as.

  • {{$customer->BillAddr->Line1 }}
  • {{$customer->['BillAddr']['Line1'] }}
  • {{$customer['BillAddr']['Line1'] }}

etc..

I'm getting the error

errorException Trying to get property 'Line1' of non-object

If I try to access the property like this

$customer->BillAddr['Line1'] 

Then I also get an error, but its a different error.

Cannot use object of type QuickBooksOnline\API\Data\IPPPhysicalAddress as array

2
Hi Brandon, Is the array_chunk() usage necessary for your particular project? - summea
It is only necessary to display rows with 4 columns in bootstrap. Do you think that is why this is happeneing? let me try it without it. -- Update: It's still complaining. - Brandon Broga
Hi Brandon, I'm not sure if that is the issue, but I was curious because it seems to add a little complexity to the task at hand from my at-a-glance check of that part. - summea
I tried it without the array_chunk() and i still get the same error. - Brandon Broga
Thanks for trying that. It seems to me that your $customer variable might not be getting set with a customer object. The non-object part of your error message might help support that thought. Would it be possible to show part of your related controller code that relates to this view? In cases like this, it might be helpful to temporarily add a print_r($customers); type of line in your code to check and see if that variable has any data or if it is empty. - summea

2 Answers

1
votes

So the answer was because some of the data was missing, and Laravel complains about this...

So this is the answer to solve the problem, using the optional() helper method.

{{ optional($customer->BillAddr)->Line1 }}
0
votes

Try this:

$customer->BillAddr[0]['Line1'];

Hope this will be helpful.