xxxxxxxxxx
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class DropColumnFromTable extends Migration
{
/**
* Run the migration.
*
* @return void
*/
public function up()
{
Schema::table('table_name', function (Blueprint $table) {
$table->dropColumn('column_name');
});
}
/**
* Reverse the migration (rollback).
*
* @return void
*/
public function down()
{
Schema::table('table_name', function (Blueprint $table) {
$table->addColumn('data_type', 'column_name')->nullable();
});
}
}
xxxxxxxxxx
public function up()
{
Schema::table('table', function($table) {
$table->dropColumn('column_name');
});
}
xxxxxxxxxx
Schema::table('users', function (Blueprint $table) {
if (Schema::hasColumn('users', 'phone')) {
$table->dropColumn('phone');
}
});
xxxxxxxxxx
// To drop a column, use the dropColumn method on the schema builder.
// Before dropping columns from a SQLite database, you will need to add
// the doctrine/dbal dependency to your composer.json file and run the
// composer update command in your terminal to install the library:
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('votes');
});
xxxxxxxxxx
public function up()
{
Schema::table('table', function($table) {
$table->dropColumn('column_name');
});
}
xxxxxxxxxx
Class RemoveCommentViewCount extends Migration
{
public function up()
{
Schema::table('table', function($table) {
$table->dropColumn('coulmn_name');
});
}
public function down()
{
Schema::table('table', function($table) {
$table->integer('column_name');
});
}
}
xxxxxxxxxx
Class RemoveCommentViewCount extends Migration
{
public function up()
{
Schema::table('articles', function($table) {
$table->dropColumn('comment_count');
$table->dropColumn('view_count');
});
}
public function down()
{
Schema::table('articles', function($table) {
$table->integer('comment_count');
$table->integer('view_count');
});
}
}
xxxxxxxxxx
// Searched, laravel drop foreign column
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['votes', 'avatar', 'location']);
});
xxxxxxxxxx
Schema::table('articles', function($table) {
$table->dropColumn('comment_count');
$table->dropColumn('view_count');
});
xxxxxxxxxx
public function up()
{
Schema::table('tests', function (Blueprint $table) {
$table->dropColumn('name');
});
Schema::table('tests', function (Blueprint $table) {
$table->string('gender');
});
}