• How To Add New Column To Existing Table In Laravel Using Migration


    Step 1: Run the following command to create a migration file.
            php artisan make:migration alter_users_table
            (here users is the existing table name)
    Step 2: Now check your application. 1 migration file is created in path database/migrations.       
            The file name is like : 2018_09_10_102106_alter_users_table
            Here we will add 1 'user_type' field to users table. 
            Open that migration file and write the following in up() function.        
             Schema::table('users', function($table) {
               $table->string('user_type');
            });         
    Step 3: now run the following command & check your table. user_type field is added to your table.
                 php artisan migrate 
  • You might also like

    2 comments:

    1. This comment has been removed by the author.

      ReplyDelete
    2. Migration file is such a great function of Laravel Development which helps to Add new column in existing table.

      ReplyDelete