Tuesday, March 7, 2017

Laravel seeding results in Null timestamp

So i had a seeder for Languages Table (LanguageTableSeeder) as follows:

DB::table('languages')->insert([
    'name'        => 'English',
    'flag'        => '',
    'abbr'        => 'en',
    'script'    => 'Latn',
    'native'    => 'English',
    'active'    => '1',
    'default'    => '1',
]);

    $this->command->info('Language seeding successful.');

But this resulted in created_at and updated_at fields to be Null in database. i looked up the pre shipped UsersTabeSeeder and changed my LanguageTableSeeder to mach the exact same format:

DB::table('languages')->delete();

$languages = [
    [
        'name' => 'English',
        'flag' => '',
        'abbr' => 'en',
        'script' => 'Latn',
        'native' => 'English',
        'active' => '1',
        'default' => '1',
    ],
];

foreach ($languages as $language){
    Language::create($language);
}

This also resulted in created_at and updated_at fields to be Null which is odd because when i look up at Users Table in my data base they have created_at and updated_at fields to be set at the exact time of running the seeder.

So here is my question. Why is this happening? and is it necessary to use:

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

to get filled timestamp when seeding?



via Jhivan

Advertisement