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

I tried to sow the databases in my project. When I did this, only the "title" and "post", "Created_at" and "Update_at" fields are inserted, they are not changed and are displayed as 0000-00-00 00:00:00. I also tried with time () too. It works correctly in ' php artisan tink', but the results in the database are not changed.

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

}
+4
source share
5 answers

You can use new DateTime()! Hope it will be

+3
source

using

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

you format the value returned time()as mySql timestamp

+4
source

, , , . , , . MySQL,

 ALTER TABLE `talbename` 
   ADD `updatedon` TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 
   NOT NULL DEFAULT CURRENT_TIMESTAMP ;

, , ​​ , . , - PHP.

+1

OO ( DateTime)

$now = new DateTime();

$questions = array(
            'title' => 'Simple Question Title',
            'post' => 'Lorem ipsum dolor',
            'created_at' => $now->format('Y-m-d H:i:s'),
        );
0

. :

public function run()
    {
        DB::table('questions')->truncate();

        Question::create(array(
            'title' => 'Sample Question Title',
            'post' => 'Lorem ipsum dollar'
        ));

    } 
0

All Articles