Created
May 29, 2018 03:00
-
-
Save tieutantan/14b61b3d64cf0b1878ba44c29ab37b4c to your computer and use it in GitHub Desktop.
Assigned created_at, updated_at on create table in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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