Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tieutantan/14b61b3d64cf0b1878ba44c29ab37b4c to your computer and use it in GitHub Desktop.
Save tieutantan/14b61b3d64cf0b1878ba44c29ab37b4c to your computer and use it in GitHub Desktop.
Assigned created_at, updated_at on create table in Laravel
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
{
$table->increments('id');
$table->string('username', 20);
$table->string('name', 20);
$table->string('email', 200);
$table->string('password', 100);
$table->string('login_info', 200);
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->default(DB::raw('CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP'));
}
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment