Fix "Call to a member function format() on string" in Laravel

If you try to format a date in a blade template using $model->my_date_field->format(‘d.m.Y’), you may get the error message Call to a member function format() on string.

This error occurs, when Laravel doesn’t know, that the field contains a date. To fix this, add this to your model:

[...]
protected $dates = ['my_date_field'];
[...]