Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel eloquent set timestamps values upon seed

DB::table('menu_types')->insert([ 'title' => 'Footer', 'description' => str_random(10), 'created_at' => date("Y-m-d H:i:s") ]);

---------------------

Auto timestamp saving is only for Eloquent feature so you need to do manually like below for non eloquent feature

DB::table('languages')->insert([
    'name'        => 'English',
    'flag'        => '',
    'abbr'        => 'en',
    'script'    => 'Latn',
    'native'    => 'English',
    'active'    => '1',
    'default'    => '1',
    'created_at' => Carbon::now()->format('Y-m-d H:i:s'),
    'updated_at' => Carbon::now()->format('Y-m-d H:i:s')

]);
OR do it eloquently(Like you have seen in auto generated seeds like UserTableSeeder)

    $language = new Language();
    $language ->name = 'English';
    $language->flag'  = '',
    $language ->abbr  = 'en',
    $language->script ='Latn',
    $language->native ='English',
    $language->active ='1',
    $language->default ='1',
    $language->save();
Source by laracasts.com #
 
PREVIOUS NEXT
Tagged: #laravel #eloquent #set #timestamps #values #seed
ADD COMMENT
Topic
Name
9+7 =