DEV Community

Osman Forhad
Osman Forhad

Posted on

How to remove a column from Laravel table using migration

I was working with Laravel framework and i create a laravel migration table and working with it but after some times i need to remove a column from my table and its should do using laravel migration. for that what was the process i deed. i want to share may knowledge with you.

for that the very first step was. i opened my terminal and navigate to project directory after that i was run below command on my terminal:

php artisan make:migration remove_categorrystatus_from_categories --table=categories

this command create a migration file for me and then i open this file and wrote my migration schema to remove a column from my database table. when i open the fle i saw there two function one is public function up and another is public function down.

To remove a column i updated those functions which is like bellow:
//the up function is
public function up()
{
Schema::table('categories', function (Blueprint $table) {
$table->dropColumn('categorrystatus');
});
}
//the down function is
public function down()
{
Schema::table('categories', function (Blueprint $table) {
$table->dropColumn('categorrystatus');
});
}

an then i go to my terminal and run below command:

php artisan migrate

which was remove the categorrystatus column from my catgories table
.
that's it. all are done
.
Happy Coding.
osman forhad

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay