Laravel Model受保护$ dateFormat - 如何删除秒?

Platform: Laravel 5.1

Database: MySQL

I'm also using Fractal Transformers for transforming my returned data to JSON objects.

After putting this protected $dateFormat = 'Y-m-d H:i'; in my Model(note the missing :s) Carbon is throwing errors:

exception 'InvalidArgumentException' with message 'Trailing data' in C:\project1\vendor
esbot\carbon\src\Carbon\Carbon.php:425

According to the documentation this should work: https://laravel.com/docs/5.1/eloquent-mutators#date-mutators

I've tried the following:

  • Change my MySQL table structure from TIMESTAMP to DATETIME- no change
  • Changing the returned value with substr($time, 0, -3) - got errors
  • Asking in Gitter for help, got this:

I might be using a different Persistence that doesn't use the MySQL format

What does this mean?

How do I make sure Carbon::now() or MySQL is creating timestamps without seconds?

OR

How do I return only Y-m-d H:i?

You can try the following

Place the following code on your model

 protected $casts = ['date_time'=>'date'];

For carbon use the following

 Carbon::now()->format('Y-m-d H:i');