Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Wolf67's avatar

Stripe Response help

Hi all,

I'm fairly new to laravel so go easy on me!

I'm trying to get my head around Stripe but it seems I'm missing something as I can't quite get it to work.

I want to list all the previous invoices for the current user logged in, I can manage to grab the upcoming invoice fine but I'm struggling with previous list.

So in my controller I grab the previous using the code below, the JSON response is expected.

$invoices = \Stripe\Invoice::all(array("limit" => 3));

However in my view:

    @foreach ($invoices as $invoice)
        <tr>
            <td>{{ $invoice->date }}</td>
            <td>{{ $invoice->total }}</td>
        </tr>
    @endforeach

Doesn't show anything, I'm not entirely sure that I'm even querying the data right! I assume it's different if it's returning an array?

Hope someone can help before I jump out the window. :(

0 likes
7 replies
taijuten's avatar

Are you passing the invoices variable through to your view?

if so, try doing

{{dd($invoices)}}

In your view, to ensure that the data being passed your view matches the structure you want to output.

Wolf67's avatar

Yes, the variable is being passed to the view, here is the response I get.

Collection {#233 ▼ #_opts: RequestOptions {#232 ▶} #_values: array:4 [▼ "object" => "list" "has_more" => true "url" => "/v1/invoices" "data" => array:3 [▼ 0 => Invoice {#234 ▶} 1 => Invoice {#258 ▶} 2 => Invoice {#282 ▶} ] ] #_unsavedValues: Set {#235 ▶} #_transientValues: Set {#236 ▶} #_retrieveOptions: [] }

taijuten's avatar

try doing the following to show just the data, rather than the collection

{{dd($invoices->all())}}
Wolf67's avatar

That resulted in the same, however I added:

$invoices = \Stripe\Invoice::all(array("limit" => 3))->__toArray(true);

to my controller and it now returns an array of just the invoices.

array:4 [▼
  "object" => "list"
  "has_more" => true
  "url" => "/v1/invoices"
  "data" => array:3 [▼
    0 => array:31 [▼

      "date" => 1436171458
      "period_start" => 1436171458
      "period_end" => 1436171458
      "lines" => array:5 [▶]
      "subtotal" => 2500
      "total" => 2500
      "object" => "invoice"
      "attempted" => true
      "closed" => true
      "forgiven" => false
      "paid" => true
      "livemode" => false
      "attempt_count" => 1
      "amount_due" => 2500
      "currency" => "gbp"
      "starting_balance" => 0
      "ending_balance" => 0
      "next_payment_attempt" => null
      "webhooks_delivered_at" => 1436171459
   
      "discount" => null
      "application_fee" => null

      "tax_percent" => null
      "tax" => null
      "metadata" => []
      "statement_descriptor" => null
      "description" => null
      "receipt_number" => null
    ]
    1 => array:31 [▶]
    2 => array:31 [▶]
  ]
]

But my foreach loop still doesn't display the data, I get the error:

Trying to get property of non-object

I assume I'm not accessing the array correctly with $invoice->date, I've also tried $invoice->data->date and still the same?

taijuten's avatar

I find it hard to tell with the data given, but is it returning multiple invoices or just 1?

If it helps, to see the content of each loop, just do the following

@foreach ($invoices as $invoice)
        {{$invoice}}
    @endforeach

You can then see exactly what properties are available

Wolf67's avatar

Yes, 3 are invoices returned.

Using the loop above gives me this error:

htmlentities() expects parameter 1 to be string, array given (View: /home/vagrant/Code/projectmanage/resources/views/users/profile.blade.php)

Wolf67's avatar
Wolf67
OP
Best Answer
Level 2

Finally solved this, seems almost simple now but here is what fixed it.

@foreach($invoices->data as $invoice)
        <tr>
            <td>{{ $invoice->date }}</td>
            <td>{{ $invoice->amount_due }}</td>
@endforeach

Please or to participate in this conversation.