xxxxxxxxxx
public function up()
{
Schema::table('table', function($table) {
$table->dropColumn('column_name');
});
}
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
//To delete a column from a database table in Laravel, you can use the Schema::table method to modify the table schema. Here's an example of how you can use this method to delete a column:
use Illuminate\Support\Facades\Schema;
// Delete a column from the `users` table
Schema::table('users', function (Blueprint $table) {
$table->dropColumn('name');
});
//In this example, we're using the dropColumn method to delete the name column from the users table. You can use this method to delete any column from any table in your database.
//Just be sure to specify the correct table name and column name in the dropColumn method.
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
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');
});
}
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
<?php
$forge->dropColumn('table_name', 'column_1,column_2'); // by proving comma separated column names
$forge->dropColumn('table_name', ['column_1', 'column_2']); // by proving array of column names