PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, April 18, 2022

[FIXED] How to add multiple columns in already made table in Laravel?

 April 18, 2022     laravel, php     No comments   

Issue

I want to add multiple number of columns in the already made table in Laravel . How can i add multiple columns ?

I don't know how to do add columns in my table. I can only add single column one at a time.

Below given is my migration table up function.

public function up()
{
    Schema::create('matches', function (Blueprint $table) {
        $table->increments('id');
        $table->string('sports');
        $table->string('match');
        $table->string('date');
        $table->string('time');
        $table->string('teamA');
        $table->longtext('teamA_flag');
        $table->string('teamB');
        $table->longtext('teamB_flag');
        $table->string('venue');
        $table->string('status');
        $table->timestamps();
    });
}

This is my table whose name is matches. I want to add two columns using Laravel. The name of columns are: email and qualification.

I am expecting to add multiple number of columns on the table (matches). I want to add multiple number of columns in the already made table in Laravel . How can i add multiple columns ?

I don't know how to do add columns in my table. I can only add single column one at a time.


Solution

Create migration first by php artisan make:migration alter_table_matches, open migration that is created by the command.

public function up()
{
    Schema::table('matches', function (Blueprint $table) {
        $table->string('email')->nullable()->default(null);
        $table->string('qualification')->nullable()->default(null);
    });
}

then in down function

public function down()
{
    Schema::table('matches', function (Blueprint $table) {
        $table->dropColumn('email');
        $table->dropColumn('qualification');
    });
}


Answered By - Regolith
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing