Laravel Database Migration
How can we apply our migrations?
php artisan migrate
What does a migration file look like?
The migration file contains PHP code that either create the table or column. These are not SQL code. The up function contains new changes. The down function contains code for the rollback procedure.
<?php
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'); // add an auto_increment column name id
$table->timestamps();
$table->string('email'); // add a string column name email
$table->string('first_name'); // add a string column with the column name first_name
$table->string('password'); // add a string column with the column name password
$table->rememberToken();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
page revision: 1, last edited: 22 Oct 2016 08:28





