xxxxxxxxxx
migration add column to existing table in laravel 6
xxxxxxxxxx
php artisan make:migration add_paid_to_users_table --table=users
public function up()
{
Schema::table('users', function($table) {
$table->integer('paid');
});
}
public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('paid');
});
}
php artisan migrate
xxxxxxxxxx
public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('paid');
});
}
xxxxxxxxxx
Schema::table('table_name', function (Blueprint $table) {
$table->string('column_name', 255)->nullable()->after('previous_column_name');
});
xxxxxxxxxx
#single migration file create command
php artisan make:migration add_delivery_time_to_carts_table --table=carts
xxxxxxxxxx
public function up()
{
Schema::table('users', function($table) {
$table->integer('paid');
});
}
xxxxxxxxxx
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddNewColumnToTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('your_table_name', function (Blueprint $table) {
$table->string('new_column_name')->nullable();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('your_table_name', function (Blueprint $table) {
$table->dropColumn('new_column_name');
});
}
}