Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] Add dropColumns method on the schema class #34720

Merged
merged 2 commits into from Oct 7, 2020

Conversation

imanghafoori1
Copy link
Contributor

@imanghafoori1 imanghafoori1 commented Oct 7, 2020

This thin wrapper, adds a little bit of syntactic sugar for down methods in migrations:

refactor this:

public function down()
{
    Schema::table('posts', function (Blueprint $table) {
        $table->dropColumn('user_id');
        $table->dropColumn('state');
    });
}

into:

public function down()
{
    Schema::dropColumns('posts', ['user_id', 'state']);
}
  • Since the Illuminate\Database\Schema\Builder class is Not macroable, it is not very like to break something.
    The only possible case is, if someone has extended the Builder class, and has the same method name in the subclass but with a different signature, which is very unlikely.

  • If accepted, I will add tests in another PR.

@imanghafoori1
Copy link
Contributor Author

imanghafoori1 commented Oct 7, 2020

the method signature can also be like this:

public function dropColumns($table, ...$columns) 
{
    ...
}

to allow :

public function down()
{
    Schema::dropColumns('projects', 'user_id', 'state');
}

but I do not think it is very a pleasant API.

@taylorotwell taylorotwell merged commit 12d6a4e into laravel:8.x Oct 7, 2020
@imanghafoori1 imanghafoori1 deleted the drop_columns branch October 7, 2020 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants