When running the following in Laravel Artisan Tinker:
$article = new App\Article;
$article->published_at = Carbon\Carbon::now();
I get this error:
InvalidArgumentException with message 'Trailing data'
However, Carbon\Carbon::now()
on it's own returns a Carbon
instance as expected.
published_at
should be mutated into Carbon instance via protected $dates = ['published_at'];
in the model and it's also included in protected $fillable
.
Anyone know what's going on here or how I can resolve?
EDIT: Same thing happens when ran in a closure in routes, so not specific to Tinker
EDIT 2: Looks like others are experiencing this: https://laracasts.com/discuss/channels/general-discussion/carboncarbonnow-giving-error and twice in comments for https://laracasts.com/series/laravel-5-fundamentals/episodes/8
EDIT 3: Pretty much exactly the same code as the first example is used in https://laracasts.com/series/laravel-5-fundamentals/episodes/15 at 15:10 without error.
EDIT 4: Swapping line 2 of the above code to $article->published_at = Carbon::now()->format('Y-m-d');
works fine and even includes time when stored in the database (although not sure why).
I'd guess that "trailing data" could refer to the full datetime being too long, but seems strange that Laravel does so much with datetimes automatically (auto-converting to Carbon instances, for example) but not this.
Usage in Edit 3 would be preferable though!
now()
method. Is there any chance something is wrong with your timezone settings? What does the timezone configuration look like inconfig/app.php
? – Monicamonie'timezone' => 'UTC',
– Burgasreturn new DateTimeZone(date_default_timezone_get());
during class construction. If that doesn't lead you anywhere I doubt there is anything you can do except using native date functions. – Monicamonie