Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Laravel seed timestamps columns

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();
Comment

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();
Comment

PREVIOUS NEXT
Code Example
Php :: php bubble sort 
Php :: get today datetime in php 
Php :: php check string size 
Php :: php mysql if not exists insert 
Php :: laravel check if field has changed 
Php :: open php tag 
Php :: php array remove value if exists 
Php :: php array_reverse keep keys 
Php :: check file size validation laravel 
Php :: strtoupper 
Php :: how to load data from .env file in php 
Php :: PHP Max Input Vars 
Php :: laravel where update query 
Php :: Warning: mysqli_fetch_all() expects parameter 1 to be mysqli_result, bool given in C: ewxammphtdocslearnindex.php on line 11 
Php :: laravel collect where not 
Php :: php set global variables from function 
Php :: object values to array php 
Php :: wordpress remove add new button 
Php :: laravel storage get file path 
Php :: aravel 8 how to order by using eloquent orm 
Php :: laravel where first 
Php :: php json string to associative array 
Php :: laravel check if request wantsjson 
Php :: server cmd php 
Php :: if browser url is having query string after domain name in it check using php 
Php :: php curl asyc 
Php :: showing php code in browser 
Php :: laravel eloquent where id not equal to 
Php :: minus 1 year php 
Php :: date and time in php 
ADD CONTENT
Topic
Content
Source link
Name
1+5 =