Skip to content

Instantly share code, notes, and snippets.

@tajidyakub
Last active September 6, 2017 15:49
Show Gist options
  • Save tajidyakub/158a43d982789ce93c24072a741839c5 to your computer and use it in GitHub Desktop.
Save tajidyakub/158a43d982789ce93c24072a741839c5 to your computer and use it in GitHub Desktop.
Memberikan nilai default pada column hasil migration $table->timestamp() di Laravel

Untuk memberikan nilai default yaitu CURRENT_TIMESTAMP di column created_at dan set current timestamp on update pada column updated_at lakukan modifikasi di file migrations table users di dalam direktori ./database/migrations

<?php
  // hapus baris berikut
  $table->timestamp();
  // diganti menjadi seperti di bawah
  $table->timestamp('created_at')->default(\DB::raw('CURRENT_TIMESTAMP'));
  $table->timestamp('updated_at')->default(\DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));

?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment