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

pimous's avatar

Problem with displaying date with custom format

Hello, I would like to display a date with a specific format, so in my view I have

{!! $order-> created_at->format( 'd.m.Y') !!}

The date is displayed correctly.

But for a second field ($ table->timestamp( 'paid_at')) it does work and the code is similar :

{!! $order-> paid_at->format( 'd.m.Y')} !!}

I have this error :

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

Why ? And how can I fix it?

0 likes
2 replies
pimous's avatar
pimous
OP
Best Answer
Level 2

I found the solution

Model Order

protected $dates = ['paid_at'];
kahriman's avatar

By default, Eloquent will convert the created_at and updated_at columns to instances of Carbon, which provides an assortment of helpful methods, and extends the native PHP DateTime class.

You may customize which fields are automatically mutated, and even completely disable this mutation, by overriding the $dates property of your model:

https://laravel.com/docs/5.2/eloquent-mutators#date-mutators


namespace App;

use Illuminate\Database\Eloquent\Model;

class Order extends Model { /** * The attributes that should be mutated to dates. * * @var array */ protected $dates = ['created_at', 'updated_at', 'paid_at']; }

1 like

Please or to participate in this conversation.