7

I am building a webservice based on the latest version of Lumen to use with a Guzzle 6 client. The webservice is working but when I acces a carbon date on the client with:

$newsitem->publish_start->formatLocalized('%A %d %B %Y')

I get the following error:

Call to a member function formatLocalized() on a non-object

In my webservice 'News' model part I have:

protected $dates = [
    'publish_start',
    'publish_end'
];

If I remove these and access the date with

date('Y/m', strtotime($newsitem->publish_start))

it all works fine.

What am I missing here? How do I get Carbon dates through the webservice? Do I have to activate Carbon manually on Lumen?

2
  • What happens if you do Carbon::parse($newsitem->publish_start)->formatLocalized('%A %d %B %Y') ? Commented Dec 15, 2015 at 20:58
  • Is $newsitem actually an instance of your News model? Also what column type is publish_start? Commented Dec 16, 2015 at 11:10

1 Answer 1

5

You must include the Carbon namespace at the top of your file.

use Carbon\Carbon;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.