Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

0000-00-00 00:00:00 in timestamp

Tags:

php

laravel-4

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);
    }

}
like image 622
Naing Lin Aung Avatar asked Feb 14 '23 12:02

Naing Lin Aung


1 Answers

by using

'created_at' => date('Y-m-d H:i:s', time());

you format the value returned by time() as a mySql timestamp

like image 114
Paolo Avatar answered Feb 17 '23 02:02

Paolo