xxxxxxxxxx
#single migration file create command
php artisan make:migration add_delivery_time_to_carts_table --table=carts
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
php artisan make:migration add_paid_to_users_table --table=users
public function up()
{
Schema::table('users', function($table) {
$table->integer('paid')->after('status');
});
}
public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('paid');
});
}
php artisan migrate
xxxxxxxxxx
**STEP 1**
php artisan make:migration add_sex_to_users_table --table=users
**STEP 2**
In the new generated migration file, you will find up and down hook methods. in up hook, add there columns that you want to add, and in down hook, add there columns that you need to remove. for example, Me i need to add sex on column of users, so I will add there following line in the up hook.
$table->integer('quantity')->default(1)->nullable();
So i have something like this
public function up()
{
Schema::table('service_subscriptions', function (Blueprint $table) {
$table->integer('quantity')->default(1)->nullable();
});
}
**STEP 3**
Run the migration command as follows
php artisan migrate
Then you will have a new collumn added!!!!
THANK ME LATER!
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
Schema::table('users', function (Blueprint $table) {
$table->dateTime('verify_date')->nullable()->after("password_updated_at");
});
xxxxxxxxxx
public function up()
{
Schema::table('users', function($table) {
$table->integer('paid');
});
}
public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('paid');
});
}
xxxxxxxxxx
// The table method on the Schema facade MAY BE USED TO UPDATE EXISTING TABLES.
// The table method accepts two arguments: the name of the table and a Closure
// that receives a Blueprint instance you may use to add columns to the table:
Schema::table('users', function (Blueprint $table) {
$table->string('email');
});