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'];
[...]
Related Posts
- Fix "Failed to get metadata: Local: Broker transport failure" When Updating Sentry
- Add self hosted Google Fonts to your Laravel App
- Avoid WPForms Spam by Implementing a Custom Honeypot
- Install Laravel in Cloud9 PHP Workspace
- Setup Xdebug in Laravel Valet with PHP 7.4 and PHPStorm
- Use Google Fonts Locally With GeneratePress