-1

I got this query $paid_at = $invoice->payments->last()->paid_at which works just fine, returning a string with a date "2013-04-04" (dd, var_dump, print_r confirmed it). But when I feed it to Carbon $paid = new Carbon($paid_at);I suddenly get this error:

ErrorException (E_NOTICE)

Trying to get property of non-object

$paid = new Carbon("2013-04-04"); works just fine too... Same with \DateTime.

Am I missing something here?

Community
  • 1
  • 1
Vitalij
  • 658
  • 8
  • 22

1 Answers1

2

In your payment class add following property-

protected $dates = [
    'paid_at',
];

It will convert the paid_at column to instances of Carbon automatically.

And then you can run -

$invoice->payments->last()->paid_at; // returns instances of Carbon

Docs

Amit Gupta
  • 17,072
  • 4
  • 41
  • 53
  • Thank you for the suggestion, but I really need to get to the bottom of this issue. Why is this happening? – Vitalij Nov 03 '16 at 01:52