I was trying to seed databases in my project. When I did, only 'title' and 'post' fields are inserted, 'Created_at' and 'Updated_at' are not are not changed and show as 0000-00-00 00:00:00. I also tried with time() too. It properly work in 'php artisan tink
' but still no results are changed in database.
<?php
class QuestionsTableSeeder extends Seeder {
public function run()
{
DB::table('questions')->truncate();
$questions = array(
'title' => 'Simple Question Title',
'post' => 'Lorem ipsum dolor',
'created_at' => time()
);
// Uncomment the below to run the seeder
DB::table('questions')->insert($questions);
}
}
by using
'created_at' => date('Y-m-d H:i:s', time());
you format the value returned by time()
as a mySql timestamp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With