xxxxxxxxxx
Add Laravel enmu migration :
------------------------------
$table->enum('question_type', ['objective', 'subjective', 'multiple_choice']);
Update Laravel enum migration :
---------------------------------
DB::statement("ALTER TABLE users CHANGE COLUMN permissions permissions ENUM('admin', 'user', 'candidate') NOT NULL DEFAULT 'user'");
xxxxxxxxxx
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('leads', function (Blueprint $table)
{
//Give the moving column a temporary name:
Schema::table('leads', function($table)
{
$table->renameColumn('status', 'status_old');
});
//Add a new column with the regular name:
Schema::table('leads', function(Blueprint $table)
{
$table-> enum('status',['active', 'inactive', 'cancelled'])->nullable()->after('lead_source_id');
});
//Copy the data across to the new column:
DB::table('leads')->update([
'status' => DB::raw('status_old')
]);
//Remove the old column:
Schema::table('leads', function(Blueprint $table)
{
$table->dropColumn('status_old');
});
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
Schema::table('leads', function (Blueprint $table)
{
//Give the moving column a temporary name:
Schema::table('leads', function($table)
{
$table->renameColumn('status', 'status_old');
});
//Add a new column with the regular name:
Schema::table('leads', function(Blueprint $table)
{
$table-> enum('status',['active', 'inactive'])->nullable()->after('lead_source_id');
});
//Copy the data across to the new column:
DB::table('leads')->update([
'status' => DB::raw('status_old')
]);
//Remove the old column:
Schema::table('leads', function(Blueprint $table)
{
$table->dropColumn('status_old');
});
});
}
xxxxxxxxxx
// For identifying user
$table->enum('is_admin',['1','0'])->default('1');
// For User roles
$table->enum('user_role',['admin','manager','quest'])->default('quest');
xxxxxxxxxx
DB::statement("ALTER TABLE users CHANGE COLUMN permissions permissions ENUM('admin', 'user', 'candidate') NOT NULL DEFAULT 'user'");
xxxxxxxxxx
\DB::statement("ALTER TABLE users MODIFY COLUMN role ENUM('1','2','3')");
xxxxxxxxxx
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class UpdateRoleColumn extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
//
\DB::statement("ALTER TABLE users MODIFY COLUMN role ENUM('1','2','3')");
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}