I can't seem to get a timestamp in a format that my database seeder will accept.
I am running this command in php artisan tinker
:
$faker->dateTimeThisYear($max = '+1 year')->format('Y-m-d H:i:s')
Which produces:
"2015-03-17 01:26:44"
As far as I can tell, this matches the format that the database expects (0000-00-00 00:00:00
). However, when I try to seed the DB I get the following errors:
[InvalidArgumentException]
The separation symbol could not be found
Unexpected data found.
Hour can not be higher than 12
Unexpected data found.
A meridian could not be found
Every other variation I've tried including passing an actual DateTime object has not worked either. Not even this format: 'YYYY-MM-DD HH:mm:ss'
This doesn't work either:
DateTime::createFromFormat('Y-m-d H:i:s', '2000-05-05 22:22:22')
Error:
DateTime::createFromFormat() expects parameter 2 to be string, object given
Most disturbingly is that in the migrations for that column, I can specify Carbon::now()
as the default value and it works with no problem. It's only when seeding that these errors crop up. It won't even let me use Carbon::now()
when seeding.
Migration:
$table->timestamp('time_available')->default(Carbon::now());
Seeding:
$factory->define(App\AvailableMeeting::class, function (Faker\Generator $faker) {
return [
'office_id' => 1,
'worker_id' => 1,
'length_minutes' => $faker->numberBetween(14,61),
'time_available' => $faker->dateTimeThisYear('+1 year')->format('Y-m-d H:i:s') // doesn't work.. neither does Carbon::now()
];
});
Database:
Your thoughts are appreciated!